Package test_suite :: Package system_tests :: Module relax_disp
[hide private]
[frames] | no frames]

Source Code for Module test_suite.system_tests.relax_disp

   1  ############################################################################### 
   2  #                                                                             # 
   3  # Copyright (C) 2006-2014 Edward d'Auvergne                                   # 
   4  # Copyright (C) 2009 Sebastien Morin                                          # 
   5  # Copyright (C) 2013-2014 Troels E. Linnet                                    # 
   6  #                                                                             # 
   7  # This file is part of the program relax (http://www.nmr-relax.com).          # 
   8  #                                                                             # 
   9  # This program is free software: you can redistribute it and/or modify        # 
  10  # it under the terms of the GNU General Public License as published by        # 
  11  # the Free Software Foundation, either version 3 of the License, or           # 
  12  # (at your option) any later version.                                         # 
  13  #                                                                             # 
  14  # This program is distributed in the hope that it will be useful,             # 
  15  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
  16  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
  17  # GNU General Public License for more details.                                # 
  18  #                                                                             # 
  19  # You should have received a copy of the GNU General Public License           # 
  20  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
  21  #                                                                             # 
  22  ############################################################################### 
  23   
  24  # Python module imports. 
  25  from os import F_OK, access, getcwd, path, sep 
  26  from numpy import array, asarray, exp, median, inf, log, save, std, sum, zeros 
  27  from minfx.generic import generic_minimise 
  28  from random import gauss 
  29  import re, math 
  30  from sys import version_info 
  31  from tempfile import mkdtemp, NamedTemporaryFile 
  32   
  33   
  34  # relax module imports. 
  35  from auto_analyses import relax_disp 
  36  from auto_analyses.relax_disp_repeat_cpmg import DIC_KEY_FORMAT, Relax_disp_rep 
  37  from data_store import Relax_data_store; ds = Relax_data_store() 
  38  import dep_check 
  39  from lib.dispersion.variables import EXP_TYPE_CPMG_DQ, EXP_TYPE_CPMG_MQ, EXP_TYPE_CPMG_PROTON_MQ, EXP_TYPE_CPMG_PROTON_SQ, EXP_TYPE_CPMG_SQ, EXP_TYPE_CPMG_ZQ, EXP_TYPE_LIST, EXP_TYPE_R1RHO, MODEL_B14_FULL, MODEL_CR72, MODEL_CR72_FULL, MODEL_DPL94, MODEL_IT99, MODEL_LIST_ANALYTIC_CPMG, MODEL_LIST_FULL, MODEL_LIST_NUMERIC_CPMG, MODEL_LM63, MODEL_M61, MODEL_M61B, MODEL_MP05, MODEL_NOREX, MODEL_NS_CPMG_2SITE_3D_FULL, MODEL_NS_CPMG_2SITE_EXPANDED, MODEL_NS_CPMG_2SITE_STAR_FULL, MODEL_NS_R1RHO_2SITE, MODEL_NS_R1RHO_3SITE, MODEL_NS_R1RHO_3SITE_LINEAR, MODEL_PARAMS, MODEL_R2EFF, MODEL_TP02, MODEL_TAP03 
  40  from lib.errors import RelaxError 
  41  from lib.io import extract_data, get_file_path, open_read_file 
  42  from lib.spectrum.nmrpipe import show_apod_extract, show_apod_rmsd, show_apod_rmsd_dir_to_files, show_apod_rmsd_to_file 
  43  from pipe_control.mol_res_spin import display_spin, generate_spin_string, return_spin, spin_loop 
  44  from pipe_control.minimise import assemble_scaling_matrix 
  45  from pipe_control.pipes import display 
  46  from specific_analyses.relax_disp.checks import check_missing_r1 
  47  from specific_analyses.relax_disp.estimate_r2eff import estimate_r2eff 
  48  from specific_analyses.relax_disp.data import average_intensity, check_intensity_errors, generate_r20_key, get_curve_type, has_exponential_exp_type, has_r1rho_exp_type, loop_exp_frq, loop_exp_frq_offset_point, loop_exp_frq_offset_point_time, loop_time, return_grace_file_name_ini, return_param_key_from_data, spin_ids_to_containers 
  49  from specific_analyses.relax_disp.data import INTERPOLATE_DISP, INTERPOLATE_OFFSET, X_AXIS_DISP, X_AXIS_W_EFF, X_AXIS_THETA, Y_AXIS_R2_R1RHO, Y_AXIS_R2_EFF 
  50  from specific_analyses.relax_disp.model import models_info, nesting_param 
  51  from specific_analyses.relax_disp.parameters import linear_constraints 
  52  from status import Status; status = Status() 
  53  from test_suite.system_tests.base_classes import SystemTestCase 
  54   
  55  # C modules. 
  56  if dep_check.C_module_exp_fn: 
  57      from specific_analyses.relax_fit.optimisation import func_wrapper, dfunc_wrapper, d2func_wrapper 
  58      from target_functions.relax_fit import jacobian, jacobian_chi2, setup 
  59      # Call the python wrapper function to help with list to numpy array conversion. 
  60      func = func_wrapper 
  61      dfunc = dfunc_wrapper 
  62      d2func = d2func_wrapper 
  63   
  64   
65 -class Relax_disp(SystemTestCase):
66 """Class for testing various aspects specific to relaxation dispersion curve-fitting.""" 67
68 - def __init__(self, methodName='runTest'):
69 """Skip certain tests if the C modules are non-functional. 70 71 @keyword methodName: The name of the test. 72 @type methodName: str 73 """ 74 75 # Execute the base class method. 76 super(Relax_disp, self).__init__(methodName) 77 78 # Tests to skip. 79 blacklist = [ 80 'test_m61b_data_to_m61b' 81 ] 82 if methodName in blacklist: 83 status.skipped_tests.append([methodName, None, self._skip_type]) 84 85 # Missing module. 86 if not dep_check.C_module_exp_fn: 87 # The list of tests to skip. 88 to_skip = [ 89 "test_bug_atul_srivastava", 90 "test_bug_21344_sparse_time_spinlock_acquired_r1rho_fail_relax_disp", 91 "test_bug_9999_slow_r1rho_r2eff_error_with_mc", 92 "test_estimate_r2eff_err", 93 "test_estimate_r2eff_err_auto", 94 "test_estimate_r2eff_err_methods", 95 "test_finite_value", 96 "test_exp_fit", 97 "test_m61_exp_data_to_m61", 98 "test_r1rho_kjaergaard_auto", 99 "test_r1rho_kjaergaard_auto_check_graphs", 100 "test_r1rho_kjaergaard_man", 101 "test_r1rho_kjaergaard_missing_r1", 102 "test_value_write_calc_rotating_frame_params_auto_analysis" 103 ] 104 105 # Store in the status object. 106 if methodName in to_skip: 107 status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type]) 108 109 # If not scipy.optimize.leastsq. 110 if not dep_check.scipy_module: 111 # The list of tests to skip. 112 to_skip = [ 113 "test_estimate_r2eff_err_methods" 114 ] 115 116 # Store in the status object. 117 if methodName in to_skip: 118 status.skipped_tests.append([methodName, 'scipy.optimize.leastsq module', self._skip_type]) 119 120 # If not NMRPipe showApod program in PATH. 121 if not dep_check.showApod_software: 122 # The list of tests to skip. 123 to_skip = [ 124 "test_show_apod_extract", 125 "test_show_apod_rmsd", 126 "test_show_apod_rmsd_to_file", 127 "test_show_apod_rmsd_dir_to_files" 128 ] 129 130 # Store in the status object. 131 if methodName in to_skip: 132 status.skipped_tests.append([methodName, 'NMRPipe showApod program', self._skip_type]) 133 134 # If not matplotlib module 135 if not dep_check.matplotlib_module: 136 # The list of tests to skip. 137 to_skip = [ 138 "test_repeat_cpmg" 139 ] 140 141 # Store in the status object. 142 if methodName in to_skip: 143 status.skipped_tests.append([methodName, 'matplotlib module', self._skip_type])
144 145
146 - def setUp(self):
147 """Set up for all the functional tests.""" 148 149 # Create the data pipe. 150 self.interpreter.pipe.create('relax_disp', 'relax_disp') 151 152 # Create a temporary directory for dumping files. 153 ds.tmpdir = mkdtemp() 154 self.tmpdir = ds.tmpdir
155 156
157 - def setup_bug_22146_unpacking_r2a_r2b_cluster(self, folder=None, model_analyse=None, places = 7):
158 """Setup data for the catch of U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered full dispersion models. 159 160 @keyword folder: The name of the folder for the test data. 161 @type folder: str 162 @keyword model_analyse: The name of the model which will be tested. 163 @type model_analyse: str 164 """ 165 166 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 167 168 # Data. 169 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22146_unpacking_r2a_r2b_cluster'+sep+folder 170 171 ## Experiments 172 # Exp 1 173 sfrq_1 = 500.0*1E6 174 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 175 time_T2_1 = 0.05 176 ncycs_1 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 50] 177 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 178 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 179 r2eff_errs_1 = [0.0] * len(ncycs_1) 180 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 181 182 sfrq_2 = 600.0*1E6 183 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 184 time_T2_2 = 0.06 185 ncycs_2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 60] 186 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 187 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 188 r2eff_errs_2 = [0.0] * len(ncycs_2) 189 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 190 191 sfrq_3 = 700.0*1E6 192 r20_key_3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_3) 193 time_T2_3 = 0.07 194 ncycs_3 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 50, 70] 195 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 196 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 197 r2eff_errs_3 = [0.0] * len(ncycs_3) 198 exp_3 = [sfrq_3, time_T2_3, ncycs_3, r2eff_errs_3] 199 200 # Collect all exps 201 exps = [exp_1, exp_2, exp_3] 202 203 R20 = [5.1, 5.2, 5.3, 10.1, 10.2, 10.3, 6.1, 6.2, 6.3, 11.1, 11.2, 11.3, 7.1, 7.2, 7.3, 12.1, 12.2, 12.3, 8.1, 8.2, 8.3, 13.1, 13.2, 13.3] 204 dw_arr = [1.0, 2.0, 3.0, 4.0] 205 pA_arr = [0.9] 206 kex_arr = [1000.] 207 208 spins = [ 209 ['Ala', 1, 'N', {'r2a': {r20_key_1: R20[0], r20_key_2: R20[1], r20_key_3: R20[2]}, 'r2b': {r20_key_1: R20[3], r20_key_2: R20[4], r20_key_3: R20[5]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[0]}], 210 ['Ala', 2, 'N', {'r2a': {r20_key_1: R20[6], r20_key_2: R20[7], r20_key_3: R20[8]}, 'r2b': {r20_key_1: R20[9], r20_key_2: R20[10], r20_key_3: R20[11]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[1]}], 211 ['Ala', 3, 'N', {'r2a': {r20_key_1: R20[12], r20_key_2: R20[13], r20_key_3: R20[14]}, 'r2b': {r20_key_1: R20[15], r20_key_2: R20[16], r20_key_3: R20[17]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[2]}], 212 ['Ala', 4, 'N', {'r2a': {r20_key_1: R20[18], r20_key_2: R20[19], r20_key_3: R20[20]}, 'r2b': {r20_key_1: R20[21], r20_key_2: R20[22], r20_key_3: R20[23]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[3]}], 213 ] 214 215 # Create the data pipe. 216 pipe_name = 'base pipe' 217 pipe_type = 'relax_disp' 218 pipe_bundle = 'relax_disp' 219 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type, bundle = pipe_bundle) 220 221 # Generate the sequence. 222 for res_name, res_num, spin_name, params in spins: 223 self.interpreter.spin.create(res_name=res_name, res_num=res_num, spin_name=spin_name) 224 225 # Set isotope 226 self.interpreter.spin.isotope('15N', spin_id='@N') 227 228 # Now loop over the experiments, to set the variables in relax. 229 exp_ids = [] 230 for exp_i in exps: 231 sfrq, time_T2, ncycs, r2eff_errs = exp_i 232 exp_id = 'CPMG_%3.1f' % (sfrq/1E6) 233 exp_ids.append(exp_id) 234 235 ids = [] 236 for ncyc in ncycs: 237 nu_cpmg = ncyc / time_T2 238 cur_id = '%s_%.1f' % (exp_id, nu_cpmg) 239 ids.append(cur_id) 240 241 # Set the spectrometer frequency. 242 self.interpreter.spectrometer.frequency(id=cur_id, frq=sfrq) 243 244 # Set the experiment type. 245 self.interpreter.relax_disp.exp_type(spectrum_id=cur_id, exp_type=EXP_TYPE_CPMG_SQ) 246 247 # Set the relaxation dispersion CPMG constant time delay T (in s). 248 self.interpreter.relax_disp.relax_time(spectrum_id=cur_id, time=time_T2) 249 250 # Set the relaxation dispersion CPMG frequencies. 251 self.interpreter.relax_disp.cpmg_setup(spectrum_id=cur_id, cpmg_frq=nu_cpmg) 252 253 print("\n\nThe experiment IDs are %s." % cdp.spectrum_ids) 254 255 ### Now do fitting. 256 # Change pipe. 257 258 pipe_name_MODEL = "%s_%s"%(pipe_name, model_analyse) 259 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_MODEL, bundle_to = pipe_bundle) 260 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 261 262 # Now read data in. 263 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 264 exp_id = exp_ids[mi] 265 exp_i = exps[mi] 266 sfrq, time_T2, ncycs, r2eff_errs = exp_i 267 268 # Then loop over the spins. 269 for res_name, res_num, spin_name, params in spins: 270 cur_spin_id = ":%i@%s"%(res_num, spin_name) 271 272 # Define file name 273 file_name = "%s%s.txt" % (exp_id, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 274 275 # Read in the R2eff file to put into spin structure. 276 self.interpreter.relax_disp.r2eff_read_spin(id=exp_id, spin_id=cur_spin_id, file=file_name, dir=data_path, disp_point_col=1, data_col=2, error_col=3) 277 278 # Then select model. 279 self.interpreter.relax_disp.select_model(model=model_analyse) 280 281 # Then cluster 282 self.interpreter.relax_disp.cluster('model_cluster', ":1-100") 283 284 # Grid search 285 low_arr = R20 + dw_arr + pA_arr + kex_arr 286 self.interpreter.minimise.grid_search(lower=low_arr, upper=low_arr, inc=1, constraints=True, verbosity=1) 287 288 # Then loop over the defined spins and read the parameters. 289 for i in range(len(spins)): 290 res_name, res_num, spin_name, params = spins[i] 291 cur_spin_id = ":%i@%s"%(res_num, spin_name) 292 cur_spin = return_spin(cur_spin_id) 293 294 for mo_param in cur_spin.params: 295 print(mo_param) 296 # The R2 is a dictionary, depending on spectrometer frequency. 297 if isinstance(getattr(cur_spin, mo_param), dict): 298 for key, val in list(getattr(cur_spin, mo_param).items()): 299 should_be = params[mo_param][key] 300 print(cur_spin.model, res_name, cur_spin_id, mo_param, key, float(val), should_be) 301 self.assertAlmostEqual(val, should_be) 302 else: 303 should_be = float(params[mo_param]) 304 val = getattr(cur_spin, mo_param) 305 print(cur_spin.model, res_name, cur_spin_id, mo_param, val, should_be) 306 self.assertAlmostEqual(val, should_be) 307 308 # Test chi2. 309 # At this point the chi-squared value at the solution should be zero, as the relaxation data was created with the same parameter values. 310 self.assertAlmostEqual(cur_spin.chi2, 0.0, places = places)
311 312
313 - def setup_r1rho_kjaergaard(self, cluster_ids=[], read_R1=True):
314 """Set up the data for the test_r1rho_kjaergaard_*() system tests.""" 315 316 # The path to the data files. 317 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 318 319 # Set pipe name, bundle and type. 320 ds.pipe_name = 'base pipe' 321 ds.pipe_bundle = 'relax_disp' 322 ds.pipe_type = 'relax_disp' 323 324 # Create the data pipe. 325 self.interpreter.pipe.create(pipe_name=ds.pipe_name, bundle=ds.pipe_bundle, pipe_type=ds.pipe_type) 326 327 # Read the spins. 328 self.interpreter.spectrum.read_spins(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 329 330 # Name the isotope for field strength scaling. 331 self.interpreter.spin.isotope(isotope='15N') 332 333 # Set number of experiments to be used. 334 NR_exp = 70 335 336 # Load the experiments settings file. 337 expfile = open(data_path+sep+'exp_parameters_sort.txt', 'r') 338 expfileslines = expfile.readlines()[:NR_exp] 339 expfile.close() 340 341 # In MHz 342 yOBS = 81.050 343 # In ppm 344 yCAR = 118.078 345 centerPPM_N15 = yCAR 346 347 ## Read the chemical shift data. 348 self.interpreter.chemical_shift.read(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 349 350 # The lock power to field, has been found in an calibration experiment. 351 spin_lock_field_strengths_Hz = {'35': 431.0, '39': 651.2, '41': 800.5, '43': 984.0, '46': 1341.11, '48': 1648.5} 352 353 # Apply spectra settings. 354 # Count settings 355 j = 0 356 for i in range(len(expfileslines)): 357 line = expfileslines[i] 358 if line[0] == "#": 359 continue 360 else: 361 # DIRN I deltadof2 dpwr2slock ncyc trim ss sfrq 362 DIRN = line.split()[0] 363 I = int(line.split()[1]) 364 deltadof2 = line.split()[2] 365 dpwr2slock = line.split()[3] 366 ncyc = int(line.split()[4]) 367 trim = float(line.split()[5]) 368 ss = int(line.split()[6]) 369 set_sfrq = float(line.split()[7]) 370 apod_rmsd = float(line.split()[8]) 371 spin_lock_field_strength = spin_lock_field_strengths_Hz[dpwr2slock] 372 373 # Calculate spin_lock time 374 time_sl = 2*ncyc*trim 375 376 # Define file name for peak list. 377 FNAME = "%s_%s_%s_%s_max_standard.ser"%(I, deltadof2, dpwr2slock, ncyc) 378 sp_id = "%s_%s_%s_%s"%(I, deltadof2, dpwr2slock, ncyc) 379 380 # Load the peak intensities. 381 self.interpreter.spectrum.read_intensities(file=FNAME, dir=data_path+sep+'peak_lists', spectrum_id=sp_id, int_method='height') 382 383 # Set the peak intensity errors, as defined as the baseplane RMSD. 384 self.interpreter.spectrum.baseplane_rmsd(error=apod_rmsd, spectrum_id=sp_id) 385 386 # Set the relaxation dispersion experiment type. 387 self.interpreter.relax_disp.exp_type(spectrum_id=sp_id, exp_type='R1rho') 388 389 # Set The spin-lock field strength, nu1, in Hz 390 self.interpreter.relax_disp.spin_lock_field(spectrum_id=sp_id, field=spin_lock_field_strength) 391 392 # Calculating the spin-lock offset in ppm, from offsets values provided in Hz. 393 frq_N15_Hz = yOBS * 1E6 394 offset_ppm_N15 = float(deltadof2) / frq_N15_Hz * 1E6 395 omega_rf_ppm = centerPPM_N15 + offset_ppm_N15 396 397 # Set The spin-lock offset, omega_rf, in ppm. 398 self.interpreter.relax_disp.spin_lock_offset(spectrum_id=sp_id, offset=omega_rf_ppm) 399 400 # Set the relaxation times (in s). 401 self.interpreter.relax_disp.relax_time(spectrum_id=sp_id, time=time_sl) 402 403 # Set the spectrometer frequency. 404 self.interpreter.spectrometer.frequency(id=sp_id, frq=set_sfrq, units='MHz') 405 406 # Add to counter 407 j += 1 408 409 410 print("Testing the number of settings") 411 print("Number of settings iterations is: %s. Number of cdp.exp_type is: %s"%(i, len(cdp.exp_type))) 412 self.assertEqual(70, len(expfileslines)) 413 self.assertEqual(69, j) 414 self.assertEqual(69, len(cdp.exp_type)) 415 416 # Cluster spins 417 for curspin in cluster_ids: 418 print("Adding spin %s to cluster"%curspin) 419 self.interpreter.relax_disp.cluster('model_cluster', curspin) 420 421 # De-select for analysis those spins who have not been clustered 422 for free_spin in cdp.clustering['free spins']: 423 print("Deselecting free spin %s"%free_spin) 424 self.interpreter.deselect.spin(spin_id=free_spin, change_all=False) 425 426 427 #Paper reference values 428 # Resi Resn R1_rad_s R1err_rad_s R2_rad_s R2err_rad_s kEX_rad_s kEXerr_rad_s phi_rad2_s2 phierr_rad2_s2 phi_ppm2 phierr_ppm2 429 # Scaling rad2_s2 to ppm2: scaling_rad2_s2 = frequency_to_ppm(frq=1/(2*pi), B0=cdp.spectrometer_frq_list[0], isotope='15N')**2 = 3.85167990165e-06 430 ds.ref = dict() 431 ds.ref[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812] 432 ds.ref[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428] 433 ds.ref[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679] 434 ds.ref[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569] 435 ds.ref[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654] 436 ds.ref[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723] 437 ds.ref[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338] 438 ds.ref[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938] 439 ds.ref[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453] 440 ds.ref[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417] 441 ds.ref[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366] 442 ds.ref[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085] 443 ds.ref[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073] 444 ds.ref[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656] 445 ds.ref[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488] 446 447 ds.guess = dict() 448 ds.guess[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812] 449 ds.guess[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428] 450 ds.guess[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679] 451 ds.guess[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569] 452 ds.guess[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654] 453 ds.guess[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723] 454 ds.guess[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338] 455 ds.guess[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938] 456 ds.guess[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453] 457 ds.guess[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417] 458 ds.guess[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366] 459 ds.guess[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085] 460 ds.guess[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073] 461 ds.guess[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656] 462 ds.guess[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488] 463 464 # Assign guess values. 465 for spin, spin_id in spin_loop(return_id=True): 466 if spin_id in cluster_ids: 467 print("spin_id %s in cluster ids"%(spin_id)) 468 spin.kex = ds.guess[spin_id][6] 469 spin.phi_ex = ds.guess[spin_id][10] 470 else: 471 print("spin_id %s NOT in cluster ids"%(spin_id)) 472 473 if read_R1: 474 # Read the R1 data 475 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7)
476 477
478 - def setup_hansen_cpmg_data(self, model=None):
479 """Set up the data for the test_hansen_cpmg_data_*() system tests. 480 481 @keyword model: The name of the model which will be tested. 482 @type model: str 483 """ 484 485 # Create the data pipe and load the base data. 486 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 487 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 488 self.interpreter.results.read(data_path+sep+'base_pipe') 489 self.interpreter.deselect.spin(':4') 490 491 # Set the nuclear isotope data. 492 self.interpreter.spin.isotope('15N') 493 494 # Create the R2eff data pipe and load the results. 495 self.interpreter.pipe.create(pipe_name='R2eff - relax_disp', pipe_type='relax_disp') 496 self.interpreter.pipe.switch(pipe_name='R2eff - relax_disp') 497 self.interpreter.results.read(data_path+sep+'r2eff_pipe') 498 self.interpreter.deselect.spin(':4') 499 500 # The model data pipe. 501 pipe_name = "%s - relax_disp" % model 502 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 503 self.interpreter.pipe.switch(pipe_name=pipe_name) 504 505 # Set the model. 506 self.interpreter.relax_disp.select_model(model=model) 507 508 # Copy the data. 509 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to=pipe_name, param='r2eff')
510 511
512 - def setup_kteilum_fmpoulsen_makke_cpmg_data(self, model=None, expfolder=None):
513 """Set up the data for the test_kteilum_fmpoulsen_makke_cpmg_data_*() system tests. 514 515 @keyword model: The name of the model which will be tested. 516 @type model: str 517 """ 518 519 # Create the data pipe and load the base data. 520 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder 521 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 522 self.interpreter.results.read(data_path+sep+'ini_setup_trunc') 523 524 # Create the R2eff data pipe and load the results. 525 self.interpreter.pipe.create(pipe_name='R2eff', pipe_type='relax_disp') 526 self.interpreter.pipe.switch(pipe_name='R2eff') 527 self.interpreter.results.read(data_path+sep+'r2eff_pipe_trunc') 528 529 # The model data pipe. 530 pipe_name = "%s - relax_disp" % model 531 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 532 self.interpreter.pipe.switch(pipe_name=pipe_name) 533 534 # Set the model. 535 self.interpreter.relax_disp.select_model(model=model) 536 537 # Copy the data. 538 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff')
539 540
541 - def setup_korzhnev_2005_data(self, data_list=[]):
542 """Set up the data for the test_korzhnev_2005_data_*() system tests using the 'NS MMQ 2-site' model. 543 544 This loads the proton-heteronuclear SQ, ZQ, DQ, and MQ (MMQ) data from: 545 546 - Dmitry M. Korzhnev, Philipp Neudecker, Anthony Mittermaier, Vladislav Yu. Orekhov, and Lewis E. Kay (2005) Multiple-site exchange in proteins studied with a suite of six NMR relaxation dispersion experiments: An application to the folding of a Fyn SH3 domain mutant. 127, 15602-15611 (U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}). 547 548 It consists of the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 549 550 551 @keyword data_list: The list of data to load. It can contain 'SQ', '1H SQ', 'ZQ', 'DQ', 'MQ', and '1H MQ'. 552 @type data_list: list of str 553 """ 554 555 # Create the data pipe and load the base data. 556 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 557 self.interpreter.pipe.create(pipe_name='Korzhnev et al., 2005', pipe_type='relax_disp') 558 559 # Create the spin system. 560 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 561 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 562 self.interpreter.spin.element('H', spin_id='@H') 563 self.interpreter.spin.element('N', spin_id='@N') 564 self.interpreter.spin.isotope('1H', spin_id='@H') 565 self.interpreter.spin.isotope('15N', spin_id='@N') 566 567 # Define the magnetic dipole-dipole relaxation interaction. 568 self.interpreter.interatom.define(spin_id1=':9@N', spin_id2=':9@H', direct_bond=True) 569 570 # The spectral data - experiment ID, R2eff file name, experiment type, spin ID string, spectrometer frequency in Hertz, relaxation time. 571 data = [ 572 ['1H SQ', '1H_SQ_CPMG_500_MHz', 'hs_500.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 500e6, 0.03], 573 ['1H SQ', '1H_SQ_CPMG_600_MHz', 'hs_600.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 600e6, 0.03], 574 ['1H SQ', '1H_SQ_CPMG_800_MHz', 'hs_800.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 800e6, 0.03], 575 ['SQ', '15N_SQ_CPMG_500_MHz', 'ns_500.res', EXP_TYPE_CPMG_SQ, ':9@N', 500e6, 0.04], 576 ['SQ', '15N_SQ_CPMG_600_MHz', 'ns_600.res', EXP_TYPE_CPMG_SQ, ':9@N', 600e6, 0.04], 577 ['SQ', '15N_SQ_CPMG_800_MHz', 'ns_800.res', EXP_TYPE_CPMG_SQ, ':9@N', 800e6, 0.04], 578 ['DQ', '15N_DQ_CPMG_500_MHz', 'dq_500.res', EXP_TYPE_CPMG_DQ, ':9@N', 500e6, 0.03], 579 ['DQ', '15N_DQ_CPMG_600_MHz', 'dq_600.res', EXP_TYPE_CPMG_DQ, ':9@N', 600e6, 0.03], 580 ['DQ', '15N_DQ_CPMG_800_MHz', 'dq_800.res', EXP_TYPE_CPMG_DQ, ':9@N', 800e6, 0.03], 581 ['ZQ', '15N_ZQ_CPMG_500_MHz', 'zq_500.res', EXP_TYPE_CPMG_ZQ, ':9@N', 500e6, 0.03], 582 ['ZQ', '15N_ZQ_CPMG_600_MHz', 'zq_600.res', EXP_TYPE_CPMG_ZQ, ':9@N', 600e6, 0.03], 583 ['ZQ', '15N_ZQ_CPMG_800_MHz', 'zq_800.res', EXP_TYPE_CPMG_ZQ, ':9@N', 800e6, 0.03], 584 ['1H MQ', '1H_MQ_CPMG_500_MHz', 'hm_500.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 500e6, 0.02], 585 ['1H MQ', '1H_MQ_CPMG_600_MHz', 'hm_600.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 600e6, 0.02], 586 ['1H MQ', '1H_MQ_CPMG_800_MHz', 'hm_800.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 800e6, 0.02], 587 ['MQ', '15N_MQ_CPMG_500_MHz', 'nm_500.res', EXP_TYPE_CPMG_MQ, ':9@N', 500e6, 0.02], 588 ['MQ', '15N_MQ_CPMG_600_MHz', 'nm_600.res', EXP_TYPE_CPMG_MQ, ':9@N', 600e6, 0.02], 589 ['MQ', '15N_MQ_CPMG_800_MHz', 'nm_800.res', EXP_TYPE_CPMG_MQ, ':9@N', 800e6, 0.02] 590 ] 591 cpmg_frqs_1h_sq = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0] 592 cpmg_frqs_sq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 593 cpmg_frqs_dq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0] 594 cpmg_frqs_zq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0] 595 cpmg_frqs_1h_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 400.0, 500.0, 600.0, 700.0, 800.0, 1000.0, 1500.0, 2000.0, 2500.0] 596 cpmg_frqs_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 597 598 # Loop over the files, reading in the data. 599 for data_type, id, file, exp_type, spin_id, H_frq, relax_time in data: 600 # Skip undesired data. 601 if data_type not in data_list: 602 continue 603 604 # Alias the CPMG frequencies. 605 if data_type == 'SQ': 606 cpmg_frqs = cpmg_frqs_sq 607 elif data_type == '1H SQ': 608 cpmg_frqs = cpmg_frqs_1h_sq 609 elif data_type == 'DQ': 610 cpmg_frqs = cpmg_frqs_dq 611 elif data_type == 'ZQ': 612 cpmg_frqs = cpmg_frqs_zq 613 elif data_type == '1H MQ': 614 cpmg_frqs = cpmg_frqs_1h_mq 615 elif data_type == 'MQ': 616 cpmg_frqs = cpmg_frqs_mq 617 618 # Loop over each CPMG frequency. 619 for cpmg_frq in cpmg_frqs: 620 # The id. 621 new_id = "%s_%s" % (id, cpmg_frq) 622 623 # Set the NMR field strength. 624 self.interpreter.spectrometer.frequency(id=new_id, frq=H_frq) 625 626 # Set the relaxation dispersion experiment type. 627 self.interpreter.relax_disp.exp_type(spectrum_id=new_id, exp_type=exp_type) 628 629 # Relaxation dispersion CPMG constant time delay T (in s). 630 self.interpreter.relax_disp.relax_time(spectrum_id=new_id, time=relax_time) 631 632 # Set the CPMG frequency. 633 self.interpreter.relax_disp.cpmg_setup(spectrum_id=new_id, cpmg_frq=cpmg_frq) 634 635 # Read the R2eff data. 636 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3) 637 638 # Change the model. 639 self.interpreter.relax_disp.select_model('NS MMQ 2-site')
640 641
642 - def setup_sod1wt_t25(self, pipe_name, pipe_type, pipe_name_r2eff, select_spin_index):
643 """Setup of data SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 644 645 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 646 'SOD1-WT' CPMG data to the CR72 dispersion model. 647 648 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 649 Data is for experiment at 25 degree Celcius. 650 """ 651 652 # Create the data pipe and load the base data. 653 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'sod1wt_t25' 654 655 # Set experiment settings. sfrq, time_T2, ncyc 656 Exps = [ 657 ["600MHz", "Z_A", 599.8908617*1E6, 0.06, [28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 50, 18, 40, 6, 12, 0, 24], ["Z_A1", "Z_A15"] ], 658 ["500MHz", "Z_B", 499.862139*1E6, 0.04, [20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0], ["Z_B1", "Z_B18"] ] ] 659 660 # Create base pipe 661 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 662 663 # Loop throug experiments 664 id_lists = [] 665 for folder, key, sfrq, time_T2, ncycs, rep_ncyss in Exps: 666 # Read spins 667 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 668 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 669 670 # Make spectrum id list 671 id_list = list(key+str(i) for i in range(len(ncycs))) 672 id_lists.append(id_list) 673 674 # Read intensities 675 self.interpreter.spectrum.read_intensities(file="128_FT.ser", dir=data_path+sep+folder, int_method='height', spectrum_id=id_list, int_col=list(range(len(id_list))) ) 676 677 # Loop over experiments 678 for i in range(len(ncycs)): 679 ncyc = ncycs[i] 680 vcpmg = ncyc/time_T2 681 682 # Test if spectrum is a reference 683 if float(vcpmg) == 0.0: 684 vcpmg = None 685 else: 686 vcpmg = round(float(vcpmg), 3) 687 688 # Set current id 689 current_id = id_list[i] 690 691 # Set the current experiment type. 692 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 693 694 # Set the NMR field strength of the spectrum. 695 self.interpreter.spectrometer.frequency(id=current_id, frq=sfrq, units='Hz') 696 697 # Relaxation dispersion CPMG constant time delay T (in s). 698 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 699 700 # Set the relaxation dispersion CPMG frequencies. 701 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 702 703 # Define replicated 704 self.interpreter.spectrum.replicated(spectrum_ids=Exps[0][5]) 705 self.interpreter.spectrum.replicated(spectrum_ids=Exps[1][5]) 706 707 # Perform error analysis 708 self.interpreter.spectrum.error_analysis(subset=id_lists[0]) 709 self.interpreter.spectrum.error_analysis(subset=id_lists[1]) 710 711 # Define isotope 712 self.interpreter.spin.isotope(isotope='15N') 713 714 ############# 715 716 # Define the 64 residues which was used for Global fitting 717 glob_assn = ["G10N-H", "D11N-H", "Q15N-H", "G16N-H", "G37N-H", "G41N-H", "L42N-H", "H43N-H", "H46N-H", "V47N-H", "E49N-H", 718 "E50N-H", "E51N-H", "N53N-H", "T54N-H", "G56N-H", "C57N-H", "T58N-H", "G61N-H", "H63aN-H", "F64aN-H", "N65aN-H", 719 "L67N-H", "S68N-H", "K70N-H", "G72N-H", "G73N-H", "K75N-H", "E78N-H", "R79N-H", "H80N-H", "V81N-H", "G82N-H", 720 "G85N-H", "N86N-H", "V87N-H", "S102N-H", "V103N-H", "I104N-H", "S105N-H", "A111N-H", "I112N-H", "R115N-H", 721 "V118N-H", "E121N-H", "A123N-H", "L126N-H", "G127N-H", "K128N-H", "G129N-H", "G130N-H", "N131N-H", "E133N-H", 722 "S134N-H", "T135N-H", "T137N-H", "G138N-H", "N139N-H", "A140N-H", "G141N-H", "S142N-H", "R143N-H", "C146N-H", "G147N-H"] 723 724 # Test number of global 725 self.assertEqual(64, len(glob_assn )) 726 727 ## Turn assignments into relax spin ids. 728 # Define regular expression search 729 r = re.compile("([a-zA-Z]+)([0-9]+)([a-zA-Z]+)") 730 731 # Create list to hold regular expression search 732 relax_glob_ids = [] 733 734 # Loop over assignments 735 for assn in glob_assn: 736 # Make match for the regular search 737 m = r.match(assn) 738 # Convert to relax spin string 739 relax_string = ":%s@%s"%(m.group(2), m.group(3)) 740 741 # Save the relax spin string and the regular search 742 relax_glob_ids.append([m.group(0), m.group(1), m.group(2), m.group(3), relax_string]) 743 744 ############# Deselect all spins, and select few spins 745 746 ## Deselect all spins, and select a few for analysis 747 self.interpreter.deselect.all() 748 749 # Select few spins 750 for i in select_spin_index: 751 self.interpreter.select.spin(spin_id=relax_glob_ids[i][4], change_all=False) 752 753 ############## 754 755 # Prepare for R2eff calculation 756 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 757 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 758 759 # Select model for points calculation 760 MODEL = "R2eff" 761 self.interpreter.relax_disp.select_model(model=MODEL) 762 # Calculate R2eff values 763 self.interpreter.minimise.calculate(verbosity=1)
764 765
766 - def setup_missing_r1_spins(self):
767 """Function for setting up a few spins for the given pipe.""" 768 769 # Path to file. 770 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 771 772 # File with spins. 773 file = open(data_path+sep+'R1_fitted_values.txt') 774 lines = file.readlines() 775 file.close() 776 777 for i, line in enumerate(lines): 778 # Make the string test 779 line_split = line.split() 780 781 if line_split[0] == "#": 782 continue 783 784 mol_name = line_split[0] 785 mol_name = None 786 res_num = int(line_split[1]) 787 res_name = line_split[2] 788 spin_num = line_split[3] 789 spin_num = None 790 spin_name = line_split[4] 791 792 # Create the spin. 793 self.interpreter.spin.create(spin_name=spin_name, spin_num=spin_num, res_name=res_name, res_num=res_num, mol_name=mol_name)
794 795
796 - def setup_tp02_data_to_ns_r1rho_2site(self, clustering=False):
797 """Setup data for the test of relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 798 799 # Reset. 800 self.interpreter.reset() 801 802 # Create the data pipe and load the base data. 803 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 804 self.interpreter.state.load(data_path+sep+'r2eff_values') 805 806 # The model data pipe. 807 model = 'NS R1rho 2-site' 808 pipe_name = "%s - relax_disp" % model 809 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 810 self.interpreter.pipe.switch(pipe_name=pipe_name) 811 812 # Set the model. 813 self.interpreter.relax_disp.select_model(model=model) 814 815 # Copy the data. 816 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 817 818 # Alias the spins. 819 spin1 = cdp.mol[0].res[0].spin[0] 820 spin2 = cdp.mol[0].res[1].spin[0] 821 822 # The R20 keys. 823 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 824 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 825 826 # Set the initial parameter values. 827 spin1.r2 = {r20_key1: 9.9963793866185, r20_key2: 15.0056724422684} 828 spin1.pA = 0.779782428085762 829 spin1.dw = 7.57855284496424 830 spin1.kex = 1116.7911285203 831 spin2.r2 = {r20_key1: 11.9983346935434, r20_key2: 18.0076097513337} 832 spin2.pA = 0.826666229688602 833 spin2.dw = 9.5732624231366 834 spin2.kex = 1380.46162655657 835 836 # Test the values when clustering. 837 if clustering: 838 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-100") 839 840 # Low precision optimisation. 841 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 842 843 # Printout. 844 print("\n\nOptimised parameters:\n") 845 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 846 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 847 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 848 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 849 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 850 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 851 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2))
852 853
854 - def test_baldwin_synthetic(self):
855 """Test synthetic data of Andrew J. Baldwin B14 model whereby the simplification R20A = R20B is assumed. 856 857 Support requst sr #3154 U{https://gna.org/support/index.php?3154}. 858 859 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>} with R20A, R20B = 2. rad/s. 860 """ 861 862 # The path to the data files. 863 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 864 865 # Create pipe 866 pipe_name = 'base pipe' 867 pipe_type = 'relax_disp' 868 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 869 870 # Create base pipe 871 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 872 873 # Generate the sequence. 874 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 875 876 # Define the isotope. 877 self.interpreter.spin.isotope('1H', spin_id='@H') 878 879 # Build the experiment IDs. 880 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 881 ncycs = [2, 4, 8, 10, 20, 40, 500] 882 ids = [] 883 for ncyc in ncycs: 884 ids.append('CPMG_%s' % ncyc) 885 886 print("\n\nThe experiment IDs are %s." % ids) 887 888 # Set up the metadata for the experiments. 889 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 890 sfrq = 200. * 1E6 891 892 # Total time of CPMG block. 893 Trelax = 0.04 894 895 # First set the 896 for i in range(len(ids)): 897 id = ids[i] 898 # Set the spectrometer frequency. 899 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 900 901 # Set the experiment type. 902 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 903 904 # Set the relaxation dispersion CPMG constant time delay T (in s). 905 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 906 907 # Set the relaxation dispersion CPMG frequencies. 908 ncyc = ncycs[i] 909 nu_cpmg = ncyc / Trelax 910 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 911 912 # Prepare for R2eff reading. 913 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 914 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 915 916 # Try reading the R2eff file. 917 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_r2a_eq_r2b_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3) 918 919 # Check the global data. 920 data = [ 921 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}], 922 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 923 ['dispersion_points', len(ncycs)], 924 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}], 925 ['exp_type_list', ['SQ CPMG']], 926 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}], 927 ['spectrometer_frq_count', 1], 928 ['spectrometer_frq_list', [sfrq]], 929 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 930 ] 931 for name, value in data: 932 # Does it exist? 933 self.assert_(hasattr(cdp, name)) 934 935 # Check the object. 936 obj = getattr(cdp, name) 937 if not isinstance(data, dict): 938 self.assertEqual(obj, value) 939 940 # Check the global dictionary data. 941 else: 942 for id in ids: 943 self.assertEqual(obj[id], value[id]) 944 945 # Check the spin data. 946 n_data = [ 947 [ 50.000000, 10.367900, 0.1], 948 [ 100.000000, 10.146849, 0.1], 949 [ 200.000000, 9.765987, 0.1], 950 [ 250.000000, 9.409789, 0.1], 951 [ 500.000000, 5.829819, 0.1], 952 [ 1000.000000, 3.191928, 0.1], 953 [ 12500.000000, 2.008231, 0.1] 954 ] 955 for disp_point, value, error in n_data: 956 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 957 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 958 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 959 960 # Generate r20 key. 961 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 962 963 ## Now prepare for MODEL calculation. 964 MODEL = "B14" 965 966 # Change pipe. 967 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 968 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 969 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 970 971 # Then select model. 972 self.interpreter.relax_disp.select_model(model=MODEL) 973 974 # Store grid and minimisations results. 975 grid_results = [] 976 mini_results = [] 977 978 # The grid search size (the number of increments per dimension). 979 # If None, use the default values. 980 #GRID = None 981 GRID = 13 982 # Perform Grid Search. 983 if GRID: 984 # Set the R20 parameters in the default grid search using the minimum R2eff value. 985 # This speeds it up considerably. 986 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 987 988 # Then do grid search. 989 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 990 991 # If no Grid search, set the default values. 992 else: 993 for param in MODEL_PARAMS[MODEL]: 994 self.interpreter.value.set(param=param, index=None) 995 # Do a grid search, which will store the chi2 value. 996 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 997 998 # Store result. 999 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1000 grid_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1001 1002 ## Now do minimisation. 1003 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 1004 set_func_tol = 1e-10 1005 set_max_iter = 1000 1006 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1007 1008 # Store result. 1009 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1010 mini_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1011 1012 # Print results. 1013 for i in range(len(grid_results)): 1014 g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1015 m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1016 print("GRID %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 1017 print("MIN %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 1018 1019 # Reference values from Baldwin.py. 1020 # Exchange rate = k+ + k- (s-1) 1021 kex = 1000. 1022 # Fractional population of excited state k+/kex 1023 pb = 0.01 1024 # deltaOmega in ppm 1025 dw_ppm = 2. 1026 #relaxation rate of ground (s-1) 1027 R2g = 2. 1028 #relaxation rate of excited (s-1) 1029 R2e = 2. 1030 1031 # Test the parameters which created the data. 1032 # This is for the 1H spin. 1033 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2[r20_key], R2g, 6) 1034 1035 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1036 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 8) 1037 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex, kex, 3)
1038 1039
1041 """Test synthetic data of Andrew J. Baldwin B14 model. Support requst sr #3154 U{https://gna.org/support/index.php?3154}. 1042 1043 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>}. 1044 """ 1045 1046 # The path to the data files. 1047 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 1048 1049 # Create pipe 1050 pipe_name = 'base pipe' 1051 pipe_type = 'relax_disp' 1052 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 1053 1054 # Create base pipe 1055 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 1056 1057 # Generate the sequence. 1058 # Generate both a 1H spin, and 15N spin. 1059 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 1060 1061 # Define the isotope. 1062 self.interpreter.spin.isotope('1H', spin_id='@H') 1063 1064 # Build the experiment IDs. 1065 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 1066 ncycs = [2, 4, 8, 10, 20, 40, 500] 1067 ids = [] 1068 for ncyc in ncycs: 1069 ids.append('CPMG_%s' % ncyc) 1070 1071 print("\n\nThe experiment IDs are %s." % ids) 1072 1073 # Set up the metadata for the experiments. 1074 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 1075 sfrq = 200. * 1E6 1076 1077 # Total time of CPMG block. 1078 Trelax = 0.04 1079 1080 # First set the 1081 for i in range(len(ids)): 1082 id = ids[i] 1083 # Set the spectrometer frequency. 1084 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 1085 1086 # Set the experiment type. 1087 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 1088 1089 # Set the relaxation dispersion CPMG constant time delay T (in s). 1090 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 1091 1092 # Set the relaxation dispersion CPMG frequencies. 1093 ncyc = ncycs[i] 1094 nu_cpmg = ncyc / Trelax 1095 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 1096 1097 # Prepare for R2eff reading. 1098 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 1099 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 1100 1101 # Try reading the R2eff file. 1102 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3) 1103 1104 # Check the global data. 1105 data = [ 1106 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}], 1107 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 1108 ['dispersion_points', len(ncycs)], 1109 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}], 1110 ['exp_type_list', ['SQ CPMG']], 1111 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}], 1112 ['spectrometer_frq_count', 1], 1113 ['spectrometer_frq_list', [sfrq]], 1114 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 1115 ] 1116 for name, value in data: 1117 # Does it exist? 1118 self.assert_(hasattr(cdp, name)) 1119 1120 # Check the object. 1121 obj = getattr(cdp, name) 1122 if not isinstance(data, dict): 1123 self.assertEqual(obj, value) 1124 1125 # Check the global dictionary data. 1126 else: 1127 for id in ids: 1128 self.assertEqual(obj[id], value[id]) 1129 1130 # Check the spin data. 1131 n_data = [ 1132 [ 50.000000, 10.286255, 0.1], 1133 [ 100.000000, 10.073083, 0.1], 1134 [ 200.000000, 9.692746, 0.1], 1135 [ 250.000000, 9.382441, 0.1], 1136 [ 500.000000, 6.312396, 0.1], 1137 [ 1000.000000, 3.957029, 0.1], 1138 [ 12500.000000, 2.880420, 0.1] 1139 ] 1140 for disp_point, value, error in n_data: 1141 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 1142 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 1143 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 1144 1145 # Generate r20 key. 1146 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 1147 1148 ## Now prepare for MODEL calculation. 1149 MODEL = "B14 full" 1150 1151 # Change pipe. 1152 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 1153 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 1154 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 1155 1156 # Then select model. 1157 self.interpreter.relax_disp.select_model(model=MODEL) 1158 1159 # Store grid and minimisations results. 1160 grid_results = [] 1161 mini_results = [] 1162 clust_results = [] 1163 1164 # The grid search size (the number of increments per dimension). 1165 # If None, use the default values. 1166 #GRID = None 1167 GRID = 13 1168 # Perform Grid Search. 1169 if GRID: 1170 # Set the R20 parameters in the default grid search using the minimum R2eff value. 1171 # This speeds it up considerably. 1172 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 1173 1174 # Then do grid search. 1175 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 1176 1177 # If no Grid search, set the default values. 1178 else: 1179 for param in MODEL_PARAMS[MODEL]: 1180 self.interpreter.value.set(param=param, index=None) 1181 # Do a grid search, which will store the chi2 value. 1182 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 1183 1184 # Store result. 1185 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1186 grid_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1187 1188 ## Now do minimisation. 1189 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 1190 set_func_tol = 1e-11 1191 set_max_iter = 10000 1192 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1193 1194 # Store result. 1195 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1196 mini_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1197 1198 print("\n# Now print before and after minimisation-\n") 1199 1200 # Print results. 1201 for i in range(len(grid_results)): 1202 g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1203 m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1204 print("GRID %s r2a=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 1205 print("MIN %s r2b=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 1206 1207 # Reference values from Baldwin.py. 1208 # Exchange rate = k+ + k- (s-1) 1209 kex = 1000. 1210 # Fractional population of excited state k+/kex 1211 pb = 0.01 1212 # deltaOmega in ppm 1213 dw_ppm = 2. 1214 #relaxation rate of ground (s-1) 1215 R2g = 2. 1216 #relaxation rate of excited (s-1) 1217 R2e = 100. 1218 1219 # Test the parameters which created the data. 1220 # This is for the 1H spin. 1221 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2a[r20_key], R2g, 3) 1222 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2b[r20_key]/100, R2e/100, 3) 1223 1224 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1225 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 6) 1226 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex/1000, kex/1000, 2)
1227 1228
1229 - def x_test_bmrb_sub_cpmg(self):
1230 """U{Task #7858: <https://gna.org/task/?7858>} Make it possible to submit CPMG experiments for BMRB. 1231 This uses CPMG data from: 1232 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE. 1233 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations. 1234 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, DOI 10.1002/prot.22886 1235 """ 1236 1237 # Define path to data 1238 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011' 1239 1240 # Read data. 1241 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins') 1242 1243 # Set element 1244 self.interpreter.spin.element(element='N', spin_id=':*@N', force=False) 1245 #self.interpreter.spin.isotope(isotope='15N', spin_id=':*@N', force=False) 1246 # Rename molecule from None to 'HEWL' 1247 self.interpreter.molecule.name(mol_id=None, name='HEWL', force=True) 1248 self.interpreter.molecule.type(mol_id='#HEWL', type='protein', force=False) 1249 1250 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1251 print(spin_id) 1252 if resn == 'C': 1253 print(resi, resn) 1254 1255 # Select the thiol state of the system. 1256 # 'all disulfide bound', 'all free', 'all other bound', 'disulfide and other bound', 'free and disulfide bound', 'free and other bound', 'free disulfide and other bound', 'not available', 'not present', 'not reported', 'unknown' 1257 self.interpreter.bmrb.thiol_state(state='not reported') 1258 1259 # relax_data.temp_calibration(ri_id=None, method=None) 1260 1261 # Call display of bmrb. 1262 self.interpreter.bmrb.display()
1263 1264
1266 """U{Bug #21081<https://gna.org/bugs/?21081>} catch, the failure of a cluster analysis when spins are deselected.""" 1267 1268 # Clear the data store. 1269 self.interpreter.reset() 1270 1271 # Load the state. 1272 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21081_disp_cluster_fail.bz2' 1273 self.interpreter.state.load(state, force=True) 1274 1275 # Model selection - to catch the failure. 1276 self.interpreter.model_selection(method='AIC', modsel_pipe='final', bundle='relax_disp', pipes=['No Rex', 'CR72'])
1277 1278
1280 """U{Bug #21460<https://gna.org/bugs/?21460>} catch, the failure due to a spectrometer frequency having no relaxation data.""" 1281 1282 # Clear the data store. 1283 self.interpreter.reset() 1284 1285 # Load the state. 1286 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21460_bad_fields.bz2' 1287 self.interpreter.state.load(state, force=True) 1288 1289 # Execute the auto-analysis (fast). 1290 relax_disp.Relax_disp.opt_func_tol = 1e-5 1291 relax_disp.Relax_disp.opt_max_iterations = 1000 1292 relax_disp.Relax_disp(pipe_name="origin - relax_disp (Thu Jan 2 13:46:44 2014)", pipe_bundle="relax_disp (Thu Jan 2 13:46:44 2014)", results_dir=self.tmpdir, models=['R2eff', 'No Rex', 'CR72', 'NS CPMG 2-site expanded'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1293 1294
1296 """U{Bug #21665<https://gna.org/bugs/?21344>} catch, the failure of an analysis of a sparse acquired R1rho dataset with missing combinations of time and spin-lock field strengths using auto_analysis.""" 1297 1298 # Clear the data store. 1299 self.interpreter.reset() 1300 1301 # Load the state. 1302 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 1303 self.interpreter.state.load(state, force=True) 1304 1305 # Execute the auto-analysis (fast). 1306 relax_disp.Relax_disp.opt_func_tol = 1e-5 1307 relax_disp.Relax_disp.opt_max_iterations = 1000 1308 relax_disp.Relax_disp(pipe_name='base pipe', pipe_bundle='relax_disp', results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1309 1310
1312 """U{Bug #21665<https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times, using minimise.calculate().""" 1313 1314 # Clear the data store. 1315 self.interpreter.reset() 1316 1317 # Load the state. 1318 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1319 self.interpreter.state.load(state, force=True) 1320 1321 # Run the calculation. 1322 self.interpreter.minimise.calculate(verbosity=1)
1323 1324
1326 """U{Bug #21665<https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times using auto_analysis.""" 1327 1328 # Clear the data store. 1329 self.interpreter.reset() 1330 1331 # Load the state. 1332 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1333 self.interpreter.state.load(state, force=True) 1334 1335 # Execute the auto-analysis (fast). 1336 relax_disp.Relax_disp.opt_func_tol = 1e-5 1337 relax_disp.Relax_disp.opt_max_iterations = 1000 1338 relax_disp.Relax_disp(pipe_name="compare_128_FT_R2eff", pipe_bundle="cpmg_disp_sod1d90a", results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1339 1340
1342 """Catch U{bug #21715<https://gna.org/bugs/?21715>}, the failure of a clustered auto-analysis due to an IndexError.""" 1343 1344 # Clear the data store. 1345 self.interpreter.reset() 1346 1347 # Load the state. 1348 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'state.bz2' 1349 self.interpreter.state.load(state, force=True) 1350 1351 # Execute the auto-analysis (fast). 1352 pre_run_dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'non_clustered' 1353 relax_disp.Relax_disp.opt_func_tol = 1e-5 1354 relax_disp.Relax_disp.opt_max_iterations = 1000 1355 relax_disp.Relax_disp(pipe_name='origin - relax_disp (Sun Feb 23 19:36:51 2014)', pipe_bundle='relax_disp (Sun Feb 23 19:36:51 2014)', results_dir=self.tmpdir, models=['R2eff', 'No Rex'], grid_inc=11, mc_sim_num=2, modsel='AIC', pre_run_dir=pre_run_dir, insignificance=1.0, numeric_only=True, mc_sim_all_models=False, eliminate=True)
1356 1357
1359 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered B14 full analysis.""" 1360 1361 # Base data setup. 1362 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='B14_full', model_analyse = MODEL_B14_FULL)
1363 1364
1366 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered CR72 full analysis.""" 1367 1368 # Base data setup. 1369 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='CR72_full', model_analyse = MODEL_CR72_FULL)
1370 1371
1373 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered NS CPMG 2SITE 3D full analysis.""" 1374 1375 # Base data setup. 1376 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_3d_full', model_analyse = MODEL_NS_CPMG_2SITE_3D_FULL)
1377 1378
1380 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered NS CPMG 2SITE STAR full analysis.""" 1381 1382 # Base data setup. 1383 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_star_full', model_analyse = MODEL_NS_CPMG_2SITE_STAR_FULL, places = 4)
1384 1385
1387 """Catch U{bug #22146<https://gna.org/bugs/?22477>}, the failure of issuing: grace.write(x_data_type='res_num', y_data_type=param) for a mixed CPMG analysis.""" 1388 1389 # Clear the data store. 1390 self.interpreter.reset() 1391 1392 # Load the state. 1393 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22477_grace_write_k_AB_mixed_analysis'+sep+'bug_22477_results.bz2' 1394 self.interpreter.state.load(state, force=True) 1395 1396 param = 'k_AB' 1397 1398 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1399 print(spin_id, spin.params) 1400 if param in spin.params: 1401 print(spin_id, spin.k_AB, spin.k_AB_err) 1402 1403 # Perform write. 1404 self.interpreter.grace.write(x_data_type='res_num', y_data_type=param, file='%s.agr'%param, dir=self.tmpdir, force=True) 1405 1406 1407 # Test the header of the value.write parameter r2. 1408 param = 'r2' 1409 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1410 1411 file = open(self.tmpdir+sep+'%s.out'%param) 1412 lines = file.readlines() 1413 file.close() 1414 1415 for i, line in enumerate(lines): 1416 # Make the string test 1417 line_split = line.split() 1418 print(line_split) 1419 1420 if len(line_split) > 1: 1421 # Break at parameter header. 1422 if line_split[0] == "#" and line_split[1] == 'mol_name': 1423 nr_split_header = len(line_split) 1424 nr_split_header_i = i 1425 break 1426 1427 # Call the line after. 1428 line_split_val = lines[nr_split_header_i + 1].split() 1429 print(line_split_val) 1430 1431 # Assert that the number of columns is equal, plus 1 for "#". 1432 self.assertEqual(nr_split_header, len(line_split_val) + 1) 1433 1434 # Test the header of the value.write for parameter r2eff. 1435 param = 'r2eff' 1436 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1437 1438 file = open(self.tmpdir+sep+'%s.out'%param) 1439 lines = file.readlines() 1440 file.close() 1441 1442 for i, line in enumerate(lines): 1443 # Make the string test 1444 line_split = line.split() 1445 print(line_split) 1446 1447 if len(line_split) > 1: 1448 # Break at parameter header. 1449 if line_split[0] == "#" and line_split[1] == 'mol_name': 1450 nr_split_header = len(line_split) 1451 nr_split_header_i = i 1452 break 1453 1454 # Call the line after. 1455 line_split_val = lines[nr_split_header_i + 1].split() 1456 print(line_split_val) 1457 1458 # Assert that the number of columns is equal, plus 1 for "#". 1459 self.assertEqual(nr_split_header, len(line_split_val) + 1)
1460 1461
1463 """Catch U{bug #9999<https://gna.org/bugs/?9999>}, The slow optimisation of R1rho R2eff error estimation with Monte Carlo simulations.""" 1464 1465 # Define path to data 1466 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff" 1467 1468 # Read data. 1469 self.interpreter.results.read(prev_data_path + sep + 'results') 1470 1471 # Now count number 1472 graph_nr = 1 1473 for exp_type, frq, offset, point in loop_exp_frq_offset_point(return_indices=False): 1474 print("\nGraph nr %i" % graph_nr) 1475 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 1476 print(exp_type, frq, offset, point, time) 1477 graph_nr += 1 1478 1479 ## Possibly do an error analysis. 1480 1481 # Check if intensity errors have already been calculated by the user. 1482 precalc = True 1483 for spin in spin_loop(skip_desel=True): 1484 # No structure. 1485 if not hasattr(spin, 'peak_intensity_err'): 1486 precalc = False 1487 break 1488 1489 # Determine if a spectrum ID is missing from the list. 1490 for id in cdp.spectrum_ids: 1491 if id not in spin.peak_intensity_err: 1492 precalc = False 1493 break 1494 1495 # Skip. 1496 if precalc: 1497 print("Skipping the error analysis as it has already been performed.") 1498 1499 else: 1500 # Loop over the spectrometer frequencies. 1501 for frq in loop_frq(): 1502 # Generate a list of spectrum IDs matching the frequency. 1503 ids = [] 1504 for id in cdp.spectrum_ids: 1505 # Check that the spectrometer frequency matches. 1506 match_frq = True 1507 if frq != None and cdp.spectrometer_frq[id] != frq: 1508 match_frq = False 1509 1510 # Add the ID. 1511 if match_frq: 1512 ids.append(id) 1513 1514 # Run the error analysis on the subset. 1515 self.interpreter.spectrum.error_analysis(subset=ids) 1516 1517 print("has_exponential_exp_type:", has_exponential_exp_type()) 1518 1519 model = 'R2eff' 1520 self.interpreter.relax_disp.select_model(model) 1521 1522 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1523 #delattr(spin, 'r2eff') 1524 #delattr(spin, 'r2eff_err') 1525 #delattr(spin, 'i0') 1526 #delattr(spin, 'i0_err') 1527 setattr(spin, 'r2eff', {}) 1528 setattr(spin, 'r2eff_err', {}) 1529 setattr(spin, 'i0', {}) 1530 setattr(spin, 'i0_err', {}) 1531 1532 # Do Grid Search 1533 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=21, constraints=True, verbosity=1) 1534 1535 # Start dic. 1536 my_dic = {} 1537 1538 # Define counter for maximum elements in the numpy array list 1539 NE = 0 1540 NS = 1 1541 NM = 0 1542 NO = 0 1543 ND = 0 1544 NT = 0 1545 1546 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1547 # Save to counter. 1548 if ei > NE: 1549 NE = ei 1550 if mi > NM: 1551 NM = mi 1552 if oi > NO: 1553 NO = oi 1554 if di > ND: 1555 ND = di 1556 1557 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1558 # Save to counter. 1559 if ti > NT: 1560 NT = ti 1561 1562 # Add 1 to counter, since index start from 0. 1563 NE = NE + 1 1564 NM = NM + 1 1565 NO = NO + 1 1566 ND = ND + 1 1567 NT = NT + 1 1568 1569 # Make data array. 1570 values_arr = zeros([NE, NS, NM, NO, ND, NT]) 1571 errors_arr = zeros([NE, NS, NM, NO, ND, NT]) 1572 times_arr = zeros([NE, NS, NM, NO, ND, NT]) 1573 struct_arr = zeros([NE, NS, NM, NO, ND, NT]) 1574 param_key_list = [] 1575 1576 1577 # Loop over each spectrometer frequency and dispersion point. 1578 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1579 # Add key to dic. 1580 my_dic[spin_id] = {} 1581 1582 # Generate spin string. 1583 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1584 1585 # Loop over the parameters. 1586 #print("Grid optimised parameters for spin: %s" % (spin_string)) 1587 1588 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1589 # Generate the param_key. 1590 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1591 1592 # Append key. 1593 param_key_list.append(param_key) 1594 1595 # Add key to dic. 1596 my_dic[spin_id][param_key] = {} 1597 1598 # Get the value. 1599 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1600 i0_value = getattr(cur_spin, 'i0')[param_key] 1601 1602 # Save to dic. 1603 my_dic[spin_id][param_key]['R2eff_value_grid'] = R2eff_value 1604 my_dic[spin_id][param_key]['i0_value_grid'] = i0_value 1605 1606 ## Now try do a line of best fit by least squares. 1607 # The peak intensities, errors and times. 1608 values = [] 1609 errors = [] 1610 times = [] 1611 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1612 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1613 values.append(value) 1614 1615 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1616 errors.append(error) 1617 times.append(time) 1618 1619 # Save to numpy arrays. 1620 values_arr[ei, 0, mi, oi, di, ti] = value 1621 errors_arr[ei, 0, mi, oi, di, ti] = error 1622 times_arr[ei, 0, mi, oi, di, ti] = time 1623 struct_arr[ei, 0, mi, oi, di, ti] = 1.0 1624 1625 # y= A exp(x * k) 1626 # w[i] = ln(y[i]) 1627 # int[i] = i0 * exp( - times[i] * r2eff); 1628 w = log(array(values)) 1629 x = - array(times) 1630 n = len(times) 1631 1632 b = (sum(x*w) - 1./n * sum(x) * sum(w) ) / ( sum(x**2) - 1./n * (sum(x))**2 ) 1633 a = 1./n * sum(w) - b * 1./n * sum(x) 1634 R2eff_est = b 1635 i0_est = exp(a) 1636 1637 my_dic[spin_id][param_key]['R2eff_est'] = R2eff_est 1638 my_dic[spin_id][param_key]['i0_est'] = i0_est 1639 1640 # Print value. 1641 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1642 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1643 1644 1645 # Do minimisation. 1646 set_func_tol = 1e-25 1647 set_max_iter = int(1e7) 1648 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1649 1650 # Loop over each spectrometer frequency and dispersion point. 1651 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1652 # Generate spin string. 1653 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1654 1655 # Loop over the parameters. 1656 print("Optimised parameters for spin: %s" % (spin_string)) 1657 1658 for exp_type, frq, offset, point in loop_exp_frq_offset_point(): 1659 # Generate the param_key. 1660 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1661 1662 # Get the value. 1663 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1664 i0_value = getattr(cur_spin, 'i0')[param_key] 1665 1666 # Extract from dic. 1667 R2eff_value_grid = my_dic[spin_id][param_key]['R2eff_value_grid'] 1668 i0_value_grid = my_dic[spin_id][param_key]['i0_value_grid'] 1669 R2eff_est = my_dic[spin_id][param_key]['R2eff_est'] 1670 i0_est = my_dic[spin_id][param_key]['i0_est'] 1671 1672 # Print value. 1673 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1674 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1675 1676 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'R2eff', "Grid : Min : Estimated:", R2eff_value_grid, R2eff_value, R2eff_est)) 1677 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'i0', "Grid : Min : Estimated:", i0_value_grid, i0_value, i0_est)) 1678 1679 print(NE, NS, NM, NO, ND, NT) 1680 for param_key in param_key_list: 1681 print(" '%s'," % param_key) 1682 print(values_arr.shape) 1683 1684 # Save arrays to profiling. 1685 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'curve_fitting'+sep+'profiling'+sep
1686 #save(data_path + "values_arr", values_arr) 1687 #save(data_path + "errors_arr", errors_arr) 1688 #save(data_path + "times_arr", times_arr) 1689 #save(data_path + "struct_arr", struct_arr) 1690 1691
1692 - def test_bug_atul_srivastava(self):
1693 """Test data from Atul Srivastava. This is a bug missing raising a Relax Error, since the setup points to a situation where the data 1694 shows it is exponential fitting, but only one time point is added per file. 1695 1696 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1718>}: 1697 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735>}: 1698 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735/focus=1736>}: 1699 1700 """ 1701 1702 # Data path. 1703 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_Atul_Srivastava' 1704 file = data_path + sep + 'bug_script.py' 1705 1706 # Run script. 1707 self.interpreter.script(file=file, dir=None) 1708 1709 # The grid search size (the number of increments per dimension). 1710 GRID_INC = 11 1711 1712 # Check-data. 1713 ################# 1714 1715 # Loop over spins, to see current setup. 1716 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1717 print(mol_name, resi, resn, spin_id) 1718 1719 # Loop over setup. 1720 for id in cdp.exp_type: 1721 print(id, cdp.exp_type[id], cdp.spectrometer_frq[id], cdp.spin_lock_offset[id], cdp.spin_lock_nu1[id]) 1722 1723 1724 # Manual minimisation. 1725 ################# 1726 if True: 1727 # Set the model. 1728 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 1729 1730 # Check if intensity errors have already been calculated. 1731 check_intensity_errors() 1732 1733 # Calculate the R2eff values for the fixed relaxation time period data types. 1734 if cdp.model_type == MODEL_R2EFF and not has_exponential_exp_type(): 1735 self.interpreter.minimise.calculate() 1736 1737 # Optimise the model. 1738 else: 1739 constraints = False 1740 min_algor = 'Newton' 1741 self.assertRaises(RelaxError, self.interpreter.minimise.grid_search, inc=GRID_INC) 1742 self.assertRaises(RelaxError, self.interpreter.minimise.execute, min_algor=min_algor, constraints=constraints) 1743 1744 # Inspect. 1745 if False: 1746 # Loop over attributes. 1747 par_attr_list = ['r2eff', 'i0'] 1748 1749 # Collect the estimation data. 1750 my_dic = {} 1751 param_key_list = [] 1752 est_keys = [] 1753 est_key = 'grid' 1754 est_keys.append(est_key) 1755 spin_id_list = [] 1756 1757 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1758 # Add key to dic. 1759 my_dic[spin_id] = {} 1760 1761 # Add key for estimate. 1762 my_dic[spin_id][est_key] = {} 1763 1764 # Add spin key to list. 1765 spin_id_list.append(spin_id) 1766 1767 # Generate spin string. 1768 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1769 1770 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1771 # Generate the param_key. 1772 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1773 #param_key = generate_r20_key(exp_type=exp_type, frq=frq) 1774 1775 # Append key. 1776 param_key_list.append(param_key) 1777 1778 # Add key to dic. 1779 my_dic[spin_id][est_key][param_key] = {} 1780 1781 # Get the value. 1782 # Loop over err attributes. 1783 for par_attr in par_attr_list: 1784 if hasattr(cur_spin, par_attr): 1785 get_par_attr = getattr(cur_spin, par_attr)[param_key] 1786 else: 1787 get_par_attr = 0.0 1788 1789 # Save to dic. 1790 my_dic[spin_id][est_key][param_key][par_attr] = get_par_attr 1791 1792 # Check number of values. 1793 values = [] 1794 errors = [] 1795 times = [] 1796 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1797 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1798 values.append(value) 1799 1800 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1801 errors.append(error) 1802 times.append(time) 1803 1804 # Save to dic. 1805 my_dic[spin_id][est_key][param_key]['values'] = values 1806 my_dic[spin_id][est_key][param_key]['errors'] = errors 1807 my_dic[spin_id][est_key][param_key]['times'] = times 1808 1809 # Analysis variables. 1810 ##################### 1811 1812 # The dispersion models. 1813 MODELS = ['R2eff', 'No Rex'] 1814 1815 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 1816 MC_NUM = 10 1817 1818 # A flag which if True will activate Monte Carlo simulations for all models. Note this will hugely increase the computation time. 1819 MC_SIM_ALL_MODELS = False 1820 1821 # The results directory. 1822 RESULTS_DIR = ds.tmpdir 1823 1824 # The directory of results of an earlier analysis without clustering. 1825 PRE_RUN_DIR = None 1826 1827 # The model selection technique to use. 1828 MODSEL = 'AIC' 1829 1830 # The flag for only using numeric models in the final model selection. 1831 NUMERIC_ONLY = False 1832 1833 # The R1rho value in rad/s by which to judge insignificance. If the maximum difference between two points on all dispersion curves for a spin is less than this value, that spin will be deselected. 1834 INSIGNIFICANCE = 1.0 1835 1836 # Auto-analysis execution. 1837 self.assertRaises(RelaxError, relax_disp.Relax_disp, pipe_name='relax_disp', results_dir=RESULTS_DIR, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, insignificance=INSIGNIFICANCE, numeric_only=NUMERIC_ONLY)
1838 1839
1841 """Test data, where peak intensities are negative in CPMG 1842 1843 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 1844 """ 1845 1846 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'bug_neg_int_acbp_cpmg_disp_048MGuHCl_40C_041223' 1847 1848 # Create the spins 1849 self.interpreter.spectrum.read_spins(file="peaks_list_max_standard.ser", dir=data_path) 1850 1851 # Name the isotope for field strength scaling. 1852 self.interpreter.spin.isotope(isotope='15N') 1853 1854 # Read the spectrum from NMRSeriesTab file. The "auto" will generate spectrum name of form: Z_A{i} 1855 self.interpreter.spectrum.read_intensities(file="peaks_list_max_standard.ser", dir=data_path, spectrum_id='auto', int_method='height') 1856 1857 # Loop over the spectra settings. 1858 ncycfile=open(data_path + sep + 'ncyc.txt', 'r') 1859 1860 # Make empty ncyclist 1861 ncyclist = [] 1862 1863 i = 0 1864 for line in ncycfile: 1865 ncyc = line.split()[0] 1866 time_T2 = float(line.split()[1]) 1867 vcpmg = line.split()[2] 1868 set_sfrq = float(line.split()[3]) 1869 rmsd_err = float(line.split()[4]) 1870 1871 # Test if spectrum is a reference 1872 if float(vcpmg) == 0.0: 1873 vcpmg = None 1874 else: 1875 vcpmg = round(float(vcpmg), 3) 1876 1877 # Add ncyc to list 1878 ncyclist.append(int(ncyc)) 1879 1880 # Set the current spectrum id 1881 current_id = "Z_A%s"%(i) 1882 1883 # Set the current experiment type. 1884 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 1885 1886 # Set the peak intensity errors, as defined as the baseplane RMSD. 1887 self.interpreter.spectrum.baseplane_rmsd(error=rmsd_err, spectrum_id=current_id) 1888 1889 # Set the NMR field strength of the spectrum. 1890 self.interpreter.spectrometer.frequency(id=current_id, frq=set_sfrq, units='MHz') 1891 1892 # Relaxation dispersion CPMG constant time delay T (in s). 1893 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 1894 1895 # Set the relaxation dispersion CPMG frequencies. 1896 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 1897 1898 i += 1 1899 1900 # Specify the duplicated spectra. 1901 self.interpreter.spectrum.replicated(spectrum_ids=['Z_A1', 'Z_A15']) 1902 1903 # Delete replicate spectrum 1904 #self.interpreter.spectrum.delete('Z_A15') 1905 1906 MODELS = [MODEL_R2EFF, MODEL_NOREX] 1907 GRID_INC = 5; MC_NUM = 3; MODSEL = 'AIC' 1908 1909 results_dir = ds.tmpdir 1910 1911 # Execute 1912 relax_disp.Relax_disp(pipe_name='relax_disp', results_dir=results_dir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 1913 1914 # Check spin less R2eff points. 1915 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 1916 # Assert that spin 4, has one less R2eff point, since one of the intensities are negative. 1917 if spin_id == ':4@N': 1918 self.assertEqual(len(cur_spin.r2eff), 14) 1919 else: 1920 self.assertEqual(len(cur_spin.r2eff), 15)
1921 1922
1923 - def test_check_missing_r1(self):
1924 """Test of the check_missing_r1() function.""" 1925 1926 # Set up some spins. 1927 self.setup_missing_r1_spins() 1928 1929 # Set variables. 1930 exp_type = 'R1rho' 1931 frq = 800.1 * 1E6 1932 1933 spectrum_id='test' 1934 1935 # Set an experiment type to the pipe. 1936 self.interpreter.relax_disp.exp_type(spectrum_id=spectrum_id, exp_type=exp_type) 1937 1938 # Set a frequency to loop through. 1939 self.interpreter.spectrometer.frequency(id=spectrum_id, frq=frq, units='Hz') 1940 1941 # Check R1 for DPL94. 1942 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 1943 self.assertEqual(check_missing_r1_return, True) 1944 1945 # Check R1 for R2eff. 1946 check_missing_r1_return = check_missing_r1(model=MODEL_R2EFF) 1947 self.assertEqual(check_missing_r1_return, False) 1948 1949 # The path to the data files. 1950 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 1951 1952 # Now load some R1 data. 1953 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 1954 1955 # Check R1. 1956 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 1957 self.assertEqual(check_missing_r1_return, False)
1958 1959
1961 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site 3D, for clustered analysis. 1962 1963 This is part of: U{Task #7807 <https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis. 1964 1965 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 1966 """ 1967 1968 # Reset. 1969 #self.interpreter.reset() 1970 1971 ## Set Experiments. 1972 model_create = 'B14' 1973 #model_create = 'NS CPMG 2-site expanded' 1974 model_analyse = 'NS CPMG 2-site 3D' 1975 1976 # Exp 1 1977 sfrq_1 = 599.8908617*1E6 1978 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 1979 time_T2_1 = 0.06 1980 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 1981 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 1982 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 1983 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 1984 1985 sfrq_2 = 499.8908617*1E6 1986 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 1987 time_T2_2 = 0.05 1988 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 1989 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 1990 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 1991 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 1992 1993 # Collect all exps 1994 exps = [exp_1, exp_2] 1995 1996 spins = [ 1997 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ], 1998 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ] 1999 ] 2000 2001 # Collect the data to be used. 2002 ds.data = [model_create, model_analyse, spins, exps] 2003 2004 # The tmp directory. None is the local directory. 2005 ds.tmpdir = ds.tmpdir 2006 2007 # The results directory. None is the local directory. 2008 #ds.resdir = None 2009 ds.resdir = ds.tmpdir 2010 2011 # Do r20_from_min_r2eff ?. 2012 ds.r20_from_min_r2eff = True 2013 2014 # Remove insignificant level. 2015 ds.insignificance = 0.0 2016 2017 # The grid search size (the number of increments per dimension). 2018 ds.GRID_INC = None 2019 2020 # The do clustering. 2021 ds.do_cluster = True 2022 2023 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2024 # The default value is 1e-25. 2025 ds.set_func_tol = 1e-1 2026 2027 # The maximum number of iterations. 2028 # The default value is 1e7. 2029 ds.set_max_iter = 1000 2030 2031 # The verbosity level. 2032 ds.verbosity = 1 2033 2034 # The rel_change WARNING level. 2035 ds.rel_change = 0.05 2036 2037 # The plot_curves. 2038 ds.plot_curves = False 2039 2040 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2041 ds.sherekhan_input = False 2042 2043 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2044 ds.opendx = False 2045 2046 # The set r2eff err. 2047 ds.r2eff_err = 0.1 2048 2049 # The print result info. 2050 ds.print_res = True 2051 2052 # Execute the script. 2053 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2054 2055 cur_spins = ds.data[2] 2056 # Compare results. 2057 for i in range(len(cur_spins)): 2058 res_name, res_num, spin_name, params = cur_spins[i] 2059 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2060 cur_spin = return_spin(cur_spin_id) 2061 2062 grid_params = ds.grid_results[i][3] 2063 2064 # Extract the clust results. 2065 min_params = ds.clust_results[i][3] 2066 # Now read the parameters. 2067 print("For spin: '%s'"%cur_spin_id) 2068 for mo_param in cur_spin.params: 2069 # The R2 is a dictionary, depending on spectrometer frequency. 2070 if isinstance(getattr(cur_spin, mo_param), dict): 2071 grid_r2 = grid_params[mo_param] 2072 min_r2 = min_params[mo_param] 2073 set_r2 = params[mo_param] 2074 for key, val in list(set_r2.items()): 2075 grid_r2_frq = grid_r2[key] 2076 min_r2_frq = min_r2[key] 2077 set_r2_frq = set_r2[key] 2078 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2079 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2080 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2081 if rel_change > ds.rel_change: 2082 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2083 print("###################################") 2084 2085 ## Make test on R2. 2086 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2087 else: 2088 grid_val = grid_params[mo_param] 2089 min_val = min_params[mo_param] 2090 set_val = params[mo_param] 2091 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2092 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2093 if rel_change > ds.rel_change: 2094 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2095 print("###################################") 2096 2097 ## Make test on parameters. 2098 if mo_param == 'dw': 2099 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2100 elif mo_param == 'kex': 2101 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2102 elif mo_param == 'pA': 2103 self.assertAlmostEqual(set_val, min_val, 2)
2104 2105
2107 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site STAR, for clustered analysis. 2108 2109 This is part of: U{Task #7807 <https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis. 2110 2111 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2112 """ 2113 2114 # Reset. 2115 #self.interpreter.reset() 2116 2117 ## Set Experiments. 2118 model_create = 'B14' 2119 #model_create = 'NS CPMG 2-site expanded' 2120 model_analyse = 'NS CPMG 2-site star' 2121 2122 # Exp 1 2123 sfrq_1 = 599.8908617*1E6 2124 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2125 time_T2_1 = 0.06 2126 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2127 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2128 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2129 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2130 2131 sfrq_2 = 499.8908617*1E6 2132 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2133 time_T2_2 = 0.05 2134 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2135 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2136 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2137 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2138 2139 # Collect all exps 2140 exps = [exp_1, exp_2] 2141 2142 spins = [ 2143 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ], 2144 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ] 2145 ] 2146 2147 # Collect the data to be used. 2148 ds.data = [model_create, model_analyse, spins, exps] 2149 2150 # The tmp directory. None is the local directory. 2151 ds.tmpdir = ds.tmpdir 2152 2153 # The results directory. None is the local directory. 2154 #ds.resdir = None 2155 ds.resdir = ds.tmpdir 2156 2157 # Do r20_from_min_r2eff ?. 2158 ds.r20_from_min_r2eff = True 2159 2160 # Remove insignificant level. 2161 ds.insignificance = 0.0 2162 2163 # The grid search size (the number of increments per dimension). 2164 ds.GRID_INC = None 2165 2166 # The do clustering. 2167 ds.do_cluster = True 2168 2169 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2170 # The default value is 1e-25. 2171 ds.set_func_tol = 1e-1 2172 2173 # The maximum number of iterations. 2174 # The default value is 1e7. 2175 ds.set_max_iter = 1000 2176 2177 # The verbosity level. 2178 ds.verbosity = 1 2179 2180 # The rel_change WARNING level. 2181 ds.rel_change = 0.05 2182 2183 # The plot_curves. 2184 ds.plot_curves = False 2185 2186 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2187 ds.sherekhan_input = False 2188 2189 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2190 ds.opendx = False 2191 2192 # The set r2eff err. 2193 ds.r2eff_err = 0.1 2194 2195 # The print result info. 2196 ds.print_res = True 2197 2198 # Execute the script. 2199 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2200 2201 cur_spins = ds.data[2] 2202 # Compare results. 2203 for i in range(len(cur_spins)): 2204 res_name, res_num, spin_name, params = cur_spins[i] 2205 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2206 cur_spin = return_spin(cur_spin_id) 2207 2208 grid_params = ds.grid_results[i][3] 2209 2210 # Extract the clust results. 2211 min_params = ds.clust_results[i][3] 2212 # Now read the parameters. 2213 print("For spin: '%s'"%cur_spin_id) 2214 for mo_param in cur_spin.params: 2215 # The R2 is a dictionary, depending on spectrometer frequency. 2216 if isinstance(getattr(cur_spin, mo_param), dict): 2217 grid_r2 = grid_params[mo_param] 2218 min_r2 = min_params[mo_param] 2219 set_r2 = params[mo_param] 2220 for key, val in list(set_r2.items()): 2221 grid_r2_frq = grid_r2[key] 2222 min_r2_frq = min_r2[key] 2223 set_r2_frq = set_r2[key] 2224 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2225 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2226 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2227 if rel_change > ds.rel_change: 2228 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2229 print("###################################") 2230 2231 ## Make test on R2. 2232 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2233 else: 2234 grid_val = grid_params[mo_param] 2235 min_val = min_params[mo_param] 2236 set_val = params[mo_param] 2237 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2238 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2239 if rel_change > ds.rel_change: 2240 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2241 print("###################################") 2242 2243 ## Make test on parameters. 2244 if mo_param == 'dw': 2245 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2246 elif mo_param == 'kex': 2247 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2248 elif mo_param == 'pA': 2249 self.assertAlmostEqual(set_val, min_val, 2)
2250 2251
2253 """Test synthetic cpmg data. 2254 2255 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with CR72. 2256 """ 2257 2258 # Reset. 2259 #self.interpreter.reset() 2260 2261 ## Set Experiments. 2262 model_create = 'NS CPMG 2-site 3D' 2263 #model_create = 'NS CPMG 2-site expanded' 2264 model_analyse = 'CR72' 2265 # Exp 1 2266 sfrq_1 = 599.8908617*1E6 2267 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2268 time_T2_1 = 0.06 2269 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2270 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2271 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2272 2273 sfrq_2 = 499.8908617*1E6 2274 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2275 time_T2_2 = 0.05 2276 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2277 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2278 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2279 2280 # Collect all exps 2281 exps = [exp_1, exp_2] 2282 2283 spins = [ 2284 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ] 2285 ] 2286 2287 # Collect the data to be used. 2288 ds.data = [model_create, model_analyse, spins, exps] 2289 2290 # The tmp directory. None is the local directory. 2291 ds.tmpdir = ds.tmpdir 2292 2293 # The results directory. None is the local directory. 2294 #ds.resdir = None 2295 ds.resdir = ds.tmpdir 2296 2297 # Do r20_from_min_r2eff ?. 2298 ds.r20_from_min_r2eff = True 2299 2300 # Remove insignificant level. 2301 ds.insignificance = 0.0 2302 2303 # The grid search size (the number of increments per dimension). 2304 ds.GRID_INC = 8 2305 2306 # The do clustering. 2307 ds.do_cluster = False 2308 2309 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2310 # The default value is 1e-25. 2311 ds.set_func_tol = 1e-9 2312 2313 # The maximum number of iterations. 2314 # The default value is 1e7. 2315 ds.set_max_iter = 1000 2316 2317 # The verbosity level. 2318 ds.verbosity = 1 2319 2320 # The rel_change WARNING level. 2321 ds.rel_change = 0.05 2322 2323 # The plot_curves. 2324 ds.plot_curves = False 2325 2326 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2327 ds.sherekhan_input = False 2328 2329 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2330 ds.opendx = False 2331 2332 # The set r2eff err. 2333 ds.r2eff_err = 0.1 2334 2335 # The print result info. 2336 ds.print_res = False 2337 2338 # Execute the script. 2339 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2340 2341 cur_spins = ds.data[2] 2342 # Compare results. 2343 for i in range(len(cur_spins)): 2344 res_name, res_num, spin_name, params = cur_spins[i] 2345 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2346 cur_spin = return_spin(cur_spin_id) 2347 2348 grid_params = ds.grid_results[i][3] 2349 min_params = ds.min_results[i][3] 2350 # Now read the parameters. 2351 print("For spin: '%s'"%cur_spin_id) 2352 for mo_param in cur_spin.params: 2353 # The R2 is a dictionary, depending on spectrometer frequency. 2354 if isinstance(getattr(cur_spin, mo_param), dict): 2355 grid_r2 = grid_params[mo_param] 2356 min_r2 = min_params[mo_param] 2357 set_r2 = params[mo_param] 2358 for key, val in list(set_r2.items()): 2359 grid_r2_frq = grid_r2[key] 2360 min_r2_frq = min_r2[key] 2361 set_r2_frq = set_r2[key] 2362 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2363 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2364 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2365 if rel_change > ds.rel_change: 2366 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2367 print("###################################") 2368 2369 ## Make test on R2. 2370 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2371 else: 2372 grid_val = grid_params[mo_param] 2373 min_val = min_params[mo_param] 2374 set_val = params[mo_param] 2375 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2376 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2377 if rel_change > ds.rel_change: 2378 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2379 print("###################################") 2380 2381 ## Make test on parameters. 2382 if mo_param == 'dw': 2383 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2384 elif mo_param == 'kex': 2385 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2386 elif mo_param == 'pA': 2387 self.assertAlmostEqual(set_val, min_val, 3)
2388 2389
2391 """Test synthetic cpmg data. 2392 2393 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with B14. 2394 Try to catch bug #22021 U{https://gna.org/bugs/index.php?22021}: Model B14 shows bad fitting to data. 2395 """ 2396 2397 # Reset. 2398 #self.interpreter.reset() 2399 2400 ## Set Experiments. 2401 model_create = 'NS CPMG 2-site 3D' 2402 #model_create = 'NS CPMG 2-site expanded' 2403 model_analyse = 'B14' 2404 # Exp 1 2405 sfrq_1 = 599.8908617*1E6 2406 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2407 time_T2_1 = 0.06 2408 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2409 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2410 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2411 2412 sfrq_2 = 499.8908617*1E6 2413 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2414 time_T2_2 = 0.05 2415 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2416 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2417 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2418 2419 # Collect all exps 2420 exps = [exp_1, exp_2] 2421 2422 spins = [ 2423 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ] 2424 ] 2425 2426 # Collect the data to be used. 2427 ds.data = [model_create, model_analyse, spins, exps] 2428 2429 # The tmp directory. None is the local directory. 2430 ds.tmpdir = ds.tmpdir 2431 2432 # The results directory. None is the local directory. 2433 #ds.resdir = None 2434 ds.resdir = ds.tmpdir 2435 2436 # Do r20_from_min_r2eff ?. 2437 ds.r20_from_min_r2eff = True 2438 2439 # Remove insignificant level. 2440 ds.insignificance = 0.0 2441 2442 # The grid search size (the number of increments per dimension). 2443 ds.GRID_INC = 8 2444 2445 # The do clustering. 2446 ds.do_cluster = False 2447 2448 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2449 # The default value is 1e-25. 2450 ds.set_func_tol = 1e-9 2451 2452 # The maximum number of iterations. 2453 # The default value is 1e7. 2454 ds.set_max_iter = 1000 2455 2456 # The verbosity level. 2457 ds.verbosity = 1 2458 2459 # The rel_change WARNING level. 2460 ds.rel_change = 0.05 2461 2462 # The plot_curves. 2463 ds.plot_curves = False 2464 2465 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2466 ds.sherekhan_input = False 2467 2468 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2469 ds.opendx = False 2470 2471 # The set r2eff err. 2472 ds.r2eff_err = 0.1 2473 2474 # The print result info. 2475 ds.print_res = False 2476 2477 # Execute the script. 2478 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2479 2480 cur_spins = ds.data[2] 2481 # Compare results. 2482 for i in range(len(cur_spins)): 2483 res_name, res_num, spin_name, params = cur_spins[i] 2484 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2485 cur_spin = return_spin(cur_spin_id) 2486 2487 grid_params = ds.grid_results[i][3] 2488 min_params = ds.min_results[i][3] 2489 # Now read the parameters. 2490 print("For spin: '%s'"%cur_spin_id) 2491 for mo_param in cur_spin.params: 2492 # The R2 is a dictionary, depending on spectrometer frequency. 2493 if isinstance(getattr(cur_spin, mo_param), dict): 2494 grid_r2 = grid_params[mo_param] 2495 min_r2 = min_params[mo_param] 2496 set_r2 = params[mo_param] 2497 for key, val in list(set_r2.items()): 2498 grid_r2_frq = grid_r2[key] 2499 min_r2_frq = min_r2[key] 2500 set_r2_frq = set_r2[key] 2501 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2502 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2503 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2504 if rel_change > ds.rel_change: 2505 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2506 print("###################################") 2507 2508 ## Make test on R2. 2509 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2510 else: 2511 grid_val = grid_params[mo_param] 2512 min_val = min_params[mo_param] 2513 set_val = params[mo_param] 2514 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2515 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2516 if rel_change > ds.rel_change: 2517 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2518 print("###################################") 2519 2520 ## Make test on parameters. 2521 if mo_param == 'dw': 2522 self.assertAlmostEqual(set_val/10, min_val/10, 5) 2523 elif mo_param == 'kex': 2524 self.assertAlmostEqual(set_val/1000, min_val/1000, 5) 2525 elif mo_param == 'pA': 2526 self.assertAlmostEqual(set_val, min_val, 6)
2527 2528
2530 """Test synthetic cpmg data. For CR72 with small noise and cluster. 2531 2532 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2533 """ 2534 2535 # Reset. 2536 #self.interpreter.reset() 2537 2538 ## Set Experiments. 2539 model_create = 'NS CPMG 2-site 3D' 2540 #model_create = 'NS CPMG 2-site expanded' 2541 model_analyse = 'CR72' 2542 2543 # Exp 1 2544 sfrq_1 = 599.8908617*1E6 2545 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2546 time_T2_1 = 0.06 2547 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2548 r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2549 #r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2550 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2551 2552 sfrq_2 = 499.8908617*1E6 2553 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2554 time_T2_2 = 0.05 2555 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2556 r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2557 #r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2558 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2559 2560 # Collect all exps 2561 exps = [exp_1, exp_2] 2562 2563 spins = [ 2564 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ], 2565 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.99, 'dw': 1.} ] 2566 ] 2567 2568 # Collect the data to be used. 2569 ds.data = [model_create, model_analyse, spins, exps] 2570 2571 # The tmp directory. None is the local directory. 2572 ds.tmpdir = ds.tmpdir 2573 2574 # The results directory. None is the local directory. 2575 #ds.resdir = None 2576 ds.resdir = ds.tmpdir 2577 2578 # Do r20_from_min_r2eff ?. 2579 ds.r20_from_min_r2eff = True 2580 2581 # Remove insignificant level. 2582 ds.insignificance = 0.0 2583 2584 # The grid search size (the number of increments per dimension). 2585 ds.GRID_INC = 13 2586 2587 # The do clustering. 2588 ds.do_cluster = True 2589 2590 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2591 # The default value is 1e-25. 2592 ds.set_func_tol = 1e-8 2593 2594 # The maximum number of iterations. 2595 # The default value is 1e7. 2596 ds.set_max_iter = 10000 2597 2598 # The verbosity level. 2599 ds.verbosity = 1 2600 2601 # The rel_change WARNING level. 2602 ds.rel_change = 0.05 2603 2604 # The plot_curves. 2605 ds.plot_curves = False 2606 2607 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2608 ds.sherekhan_input = False 2609 2610 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2611 ds.opendx = False 2612 2613 # The set r2eff err. 2614 ds.r2eff_err = 0.1 2615 2616 # The print result info. 2617 ds.print_res = False 2618 2619 # Execute the script. 2620 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2621 2622 cur_spins = ds.data[2] 2623 # Compare results. 2624 for i in range(len(cur_spins)): 2625 res_name, res_num, spin_name, params = cur_spins[i] 2626 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2627 cur_spin = return_spin(cur_spin_id) 2628 2629 grid_params = ds.grid_results[i][3] 2630 2631 # Extract the clust results. 2632 min_params = ds.clust_results[i][3] 2633 # Now read the parameters. 2634 print("For spin: '%s'"%cur_spin_id) 2635 for mo_param in cur_spin.params: 2636 # The R2 is a dictionary, depending on spectrometer frequency. 2637 if isinstance(getattr(cur_spin, mo_param), dict): 2638 grid_r2 = grid_params[mo_param] 2639 min_r2 = min_params[mo_param] 2640 set_r2 = params[mo_param] 2641 for key, val in list(set_r2.items()): 2642 grid_r2_frq = grid_r2[key] 2643 min_r2_frq = min_r2[key] 2644 set_r2_frq = set_r2[key] 2645 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2646 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2647 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2648 if rel_change > ds.rel_change: 2649 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2650 print("###################################") 2651 2652 ## Make test on R2. 2653 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2654 else: 2655 grid_val = grid_params[mo_param] 2656 min_val = min_params[mo_param] 2657 set_val = params[mo_param] 2658 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2659 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2660 if rel_change > ds.rel_change: 2661 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2662 print("###################################") 2663 2664 ## Make test on parameters. 2665 if mo_param == 'dw': 2666 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2667 elif mo_param == 'kex': 2668 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2669 elif mo_param == 'pA': 2670 self.assertAlmostEqual(set_val, min_val, 2)
2671 2672
2674 """Test synthetic cpmg data, calling the dx.map function with one or two points. 2675 2676 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2677 """ 2678 2679 # Reset. 2680 #self.interpreter.reset() 2681 2682 ## Set Experiments. 2683 model_create = MODEL_NS_CPMG_2SITE_EXPANDED 2684 model_analyse = 'CR72' 2685 # Exp 1 2686 sfrq_1 = 599.8908617*1E6 2687 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2688 time_T2_1 = 0.06 2689 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2690 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2691 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2692 2693 sfrq_2 = 499.8908617*1E6 2694 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2695 time_T2_2 = 0.05 2696 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2697 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2698 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2699 2700 # Collect all exps 2701 exps = [exp_1, exp_2] 2702 2703 spins = [ 2704 ['Ala', 1, 'N', {'r2': {r20_key_1:2, r20_key_2:2}, 'r2a': {r20_key_1:2, r20_key_2:2}, 'r2b': {r20_key_1:2, r20_key_2:2}, 'kex': 1000, 'pA': 0.99, 'dw': 2} ] 2705 ] 2706 2707 # Collect the data to be used. 2708 ds.data = [model_create, model_analyse, spins, exps] 2709 2710 # The tmp directory. None is the local directory. 2711 ds.tmpdir = ds.tmpdir 2712 2713 # The results directory. None is the local directory. 2714 #ds.resdir = None 2715 ds.resdir = ds.tmpdir 2716 2717 # Do r20_from_min_r2eff ?. 2718 ds.r20_from_min_r2eff = True 2719 2720 # Remove insignificant level. 2721 ds.insignificance = 0.0 2722 2723 # The grid search size (the number of increments per dimension). 2724 ds.GRID_INC = None 2725 2726 # The do clustering. 2727 ds.do_cluster = False 2728 2729 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2730 # The default value is 1e-25. 2731 ds.set_func_tol = 1e-9 2732 2733 # The maximum number of iterations. 2734 # The default value is 1e7. 2735 ds.set_max_iter = 1000 2736 2737 # The verbosity level. 2738 ds.verbosity = 1 2739 2740 # The rel_change WARNING level. 2741 ds.rel_change = 0.05 2742 2743 # The plot_curves. 2744 ds.plot_curves = False 2745 2746 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2747 ds.sherekhan_input = False 2748 2749 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2750 ds.opendx = False 2751 2752 # The set r2eff err. 2753 ds.r2eff_err = 0.1 2754 2755 # The print result info. 2756 ds.print_res = False 2757 2758 # Execute the script. 2759 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2760 2761 # Get the spins. 2762 cur_spins = ds.data[2] 2763 2764 # First switch pipe, since dx.map will go through parameters and end up a "bad" place. :-) 2765 ds.pipe_name_MODEL_MAP = "%s_%s_map"%(ds.pipe_name, model_analyse) 2766 self.interpreter.pipe.copy(pipe_from=ds.pipe_name, pipe_to=ds.pipe_name_MODEL_MAP, bundle_to = ds.pipe_bundle) 2767 self.interpreter.pipe.switch(pipe_name=ds.pipe_name_MODEL_MAP) 2768 2769 # Copy R2eff, but not the original parameters 2770 self.interpreter.value.copy(pipe_from=ds.pipe_name_r2eff, pipe_to=ds.pipe_name_MODEL_MAP, param='r2eff') 2771 2772 # Then select model. 2773 self.interpreter.relax_disp.select_model(model=model_analyse) 2774 2775 # Define dx.map settings. 2776 ds.dx_inc = 4 2777 ds.dx_params = ['dw', 'pA', 'kex'] 2778 2779 res_name, res_num, spin_name, params = cur_spins[0] 2780 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2781 cur_spin = return_spin(cur_spin_id) 2782 2783 print("Params for dx map is") 2784 print(ds.dx_params) 2785 print("Point param for dx map is") 2786 print(ds.dx_set_val) 2787 cur_model = model_analyse.replace(' ', '_') 2788 file_name_map = "%s_map%s" % (cur_model, cur_spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 2789 file_name_point = "%s_point%s" % (cur_model, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 2790 self.interpreter.dx.map(params=ds.dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=ds.dx_inc, lower=None, upper=None, axis_incs=10, file_prefix=file_name_map, dir=ds.resdir, point=[ds.dx_set_val, ds.dx_clust_val], point_file=file_name_point, create_par_file=True) 2791 2792 ## Check for file creation 2793 # Set filepaths. 2794 map_cfg = ds.tmpdir+sep+file_name_map+".cfg" 2795 map_net = ds.tmpdir+sep+file_name_map+".net" 2796 map_general = ds.tmpdir+sep+file_name_map+".general" 2797 map_par = get_file_path(file_name=file_name_map+".par", dir=ds.tmpdir) 2798 map_plot = get_file_path(file_name=file_name_map+".py", dir=ds.tmpdir) 2799 2800 point_general = ds.tmpdir+sep+file_name_point+".general" 2801 point_point = ds.tmpdir+sep+file_name_point 2802 point_par = get_file_path(file_name=file_name_point+".par", dir=ds.tmpdir) 2803 2804 # Test the files exists. 2805 self.assert_(access(map_cfg, F_OK)) 2806 self.assert_(access(map_net, F_OK)) 2807 self.assert_(access(map_general, F_OK)) 2808 self.assert_(access(map_par, F_OK)) 2809 self.assert_(access(map_plot, F_OK)) 2810 self.assert_(access(point_general, F_OK)) 2811 self.assert_(access(point_point, F_OK)) 2812 self.assert_(access(point_par, F_OK)) 2813 2814 # Open the files for testing. 2815 # Check the cfg file. 2816 print("\nChecking the dx map .cfg file.") 2817 res_file = [ 2818 '//'+"\n", 2819 '//'+"\n", 2820 '// time: Thu May 8 18:55:31 2014'+"\n", 2821 '//'+"\n", 2822 '// version: 3.2.0 (format), 4.3.2 (DX)'+"\n", 2823 '//'+"\n", 2824 '//'+"\n", 2825 '// panel[0]: position = (0.0164,0.0000), size = 0.2521x0.1933, startup = 1, devstyle = 1'+"\n", 2826 '// title: value = Control Panel'+"\n", 2827 '//'+"\n", 2828 '// workspace: width = 251, height = 142'+"\n", 2829 '// layout: snap = 0, width = 50, height = 50, align = NN'+"\n", 2830 '//'+"\n", 2831 '// interactor Selector[1]: num_components = 1, value = 1 '+"\n", 2832 '// selections: maximum = 2, current = 0 '+"\n", 2833 '// option[0]: name = "Colour", value = 1'+"\n", 2834 '// option[1]: name = "Grey", value = 2'+"\n", 2835 '// instance: panel = 0, x = 81, y = 6, style = Scrolled List, vertical = 1, size = 170x136'+"\n", 2836 '// label: value = Colour Selector'+"\n", 2837 '//'+"\n", 2838 '// node Image[3]:'+"\n", 2839 '// title: value = Surface'+"\n", 2840 '// depth: value = 24'+"\n", 2841 '// window: position = (0.0000,0.0400), size = 0.9929x0.9276'+"\n", 2842 ] 2843 file = open(map_cfg, 'r') 2844 lines = file.readlines() 2845 file.close() 2846 for i in range(len(res_file)): 2847 # Skip time point 2848 if i == 2: 2849 continue 2850 self.assertEqual(res_file[i], lines[i]) 2851 2852 print("\nChecking the dx map .general file.") 2853 res_file = [ 2854 'file = CR72_map_1_N'+"\n", 2855 'grid = 5 x 5 x 5'+"\n", 2856 'format = ascii'+"\n", 2857 'interleaving = field'+"\n", 2858 'majority = row'+"\n", 2859 'field = data'+"\n", 2860 'structure = scalar'+"\n", 2861 'type = float'+"\n", 2862 'dependency = positions'+"\n", 2863 'positions = regular, regular, regular, 0, 1, 0, 1, 0, 1'+"\n", 2864 ''+"\n", 2865 'end'+"\n", 2866 ] 2867 file = open(map_general, 'r') 2868 lines = file.readlines() 2869 file.close() 2870 for i in range(len(res_file)): 2871 # Skip time point 2872 #if i == 2: 2873 # continue 2874 self.assertEqual(res_file[i], lines[i]) 2875 2876 print("\nChecking the dx point .general file.") 2877 res_file = [ 2878 'file = CR72_point_1_N'+"\n", 2879 'points = 2'+"\n", 2880 'format = ascii'+"\n", 2881 'interleaving = field'+"\n", 2882 'field = locations, field0'+"\n", 2883 'structure = 3-vector, scalar'+"\n", 2884 'type = float, float'+"\n", 2885 ''+"\n", 2886 'end'+"\n", 2887 ] 2888 file = open(point_general, 'r') 2889 lines = file.readlines() 2890 file.close() 2891 for i in range(len(res_file)): 2892 # Skip time point 2893 #if i == 2: 2894 # continue 2895 self.assertEqual(res_file[i], lines[i]) 2896 2897 print("\nChecking the dx point point file.") 2898 res_file = [ 2899 '0.8 3.92 0.39964 1'+"\n", 2900 '0.76981 3.9169 0.41353 1'+"\n", 2901 ] 2902 file = open(point_point, 'r') 2903 lines = file.readlines() 2904 file.close() 2905 for i in range(len(res_file)): 2906 # Skip time point 2907 #if i == 2: 2908 # continue 2909 self.assertEqual(res_file[i], lines[i]) 2910 2911 print("\nChecking the dx point par file.") 2912 res_file = [ 2913 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n", 2914 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n", 2915 '1 1.92453 0.98961 1034.72206 6396.02770 1 1.92453 0.98961 1034.72206 6396.02770 '+"\n", 2916 ] 2917 res_file2 = [ 2918 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n", 2919 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n", 2920 '1 1.92452 0.98961 1034.72424 6396.02439 1 1.92452 0.98961 1034.72424 6396.02439 '+"\n", 2921 ] # Python 2.5 and 3.1. 2922 file = open(point_par, 'r') 2923 lines = file.readlines() 2924 file.close() 2925 for i in range(len(res_file)): 2926 if lines[i] != res_file[i] and lines[i] != res_file2[i]: 2927 self.assertEqual(res_file[i], lines[i]) 2928 2929 print("\nChecking the matplotlib surface plot file.") 2930 res_file = [ 2931 'from copy import deepcopy'+"\n", 2932 'import numpy as np'+"\n", 2933 'import scipy.interpolate'+"\n", 2934 'from numpy.ma import masked_where'+"\n", 2935 ''+"\n", 2936 'from mpl_toolkits.mplot3d import axes3d'+"\n", 2937 'import matplotlib.pyplot as plt'+"\n", 2938 'from matplotlib import cm'+"\n", 2939 ''+"\n", 2940 '# Open file and get header.'+"\n", 2941 'mapfile_name = "%s.par"'%file_name_map+"\n", 2942 'pointfile_name = "%s.par"'%file_name_point+"\n", 2943 ''+"\n", 2944 ] 2945 file = open(map_plot, 'r') 2946 lines = file.readlines() 2947 file.close() 2948 for i in range(len(res_file)): 2949 self.assertEqual(res_file[i], lines[i])
2950 2951
2953 """Test the curve type detection using the Dr. Flemming Hansen's CPMG fixed time test data.""" 2954 2955 # Reset. 2956 self.interpreter.reset() 2957 2958 # Load the base data. 2959 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 2960 self.interpreter.state.load(data_path+sep+'r2eff_values') 2961 2962 # The type. 2963 curve_type = get_curve_type(id='500_133.33.in') 2964 self.assertEqual(curve_type, 'fixed time')
2965 2966
2967 - def test_curve_type_r1rho_exponential(self, model=None):
2968 """Test the curve type detection using the 'M61' exponential test data.""" 2969 2970 # Reset. 2971 self.interpreter.reset() 2972 2973 # Load the base data. 2974 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_on_res_m61' 2975 self.interpreter.state.load(data_path+sep+'r2eff_values') 2976 2977 # The type. 2978 curve_type = get_curve_type(id='nu_2000_ncyc9') 2979 self.assertEqual(curve_type, 'exponential')
2980 2981
2982 - def test_curve_type_r1rho_fixed_time(self, model=None):
2983 """Test the curve type detection using the 'TP02' fixed time test data.""" 2984 2985 # Reset. 2986 self.interpreter.reset() 2987 2988 # Load the base data. 2989 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 2990 self.interpreter.state.load(data_path+sep+'r2eff_values') 2991 2992 # The type. 2993 curve_type = get_curve_type(id='nu_1000.0_500MHz') 2994 self.assertEqual(curve_type, 'fixed time')
2995 2996
2997 - def test_dpl94_data_to_dpl94(self):
2998 """Test the relaxation dispersion 'DPL94' model curve fitting to fixed time synthetic data.""" 2999 3000 # Fixed time variable. 3001 ds.fixed = True 3002 3003 # Execute the script. 3004 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_dpl94.py') 3005 3006 # The original parameters. 3007 i0 = [100000.0, 20000.0] 3008 r1rho_prime = [2.25, 24.0] 3009 pA = 0.7 3010 kex = 1000.0 3011 delta_omega = [1.0, 2.0] 3012 phi_ex = [] 3013 for i in range(2): 3014 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 3015 3016 # Switch to the 'DPL94' model data pipe, then check for each spin. 3017 self.interpreter.pipe.switch('DPL94 - relax_disp') 3018 spin_index = 0 3019 for spin, spin_id in spin_loop(return_id=True): 3020 # Printout. 3021 print("\nSpin %s." % spin_id) 3022 3023 # Check the fitted parameters. 3024 self.assertAlmostEqual(spin.r2['R1rho - 800.00000000 MHz']/10, r1rho_prime[spin_index]/10, 2) 3025 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 3026 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 3027 3028 # Increment the spin index. 3029 spin_index += 1
3030 3031
3032 - def test_dx_map_clustered(self):
3033 """Test making dx_map for residues under clustered calculation. 3034 3035 This uses CPMG data from: 3036 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE 3037 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations. 3038 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, U{DOI 10.1002/prot.22886<http://dx.doi.org/10.1002/prot.22886>} 3039 """ 3040 3041 # Define path to data 3042 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011' 3043 3044 # Read data. 3045 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins') 3046 3047 # Get residue of interest. 3048 cur_spin_id = ":%i@%s"%(52, 'N') 3049 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_') 3050 3051 # Get the spin container. 3052 cur_spin = return_spin(cur_spin_id) 3053 3054 # Get the chi2 value 3055 pre_chi2 = cur_spin.chi2 3056 3057 # Then do a local minimisation. 3058 #self.interpreter.select.spin(":%i@%s"%(2, 'N')) 3059 self.interpreter.minimise.calculate() 3060 3061 # Get the chi2 value after calculation. 3062 calc_chi2 = cur_spin.chi2 3063 3064 # Assert calculation is equal. 3065 self.assertAlmostEqual(pre_chi2, calc_chi2) 3066 3067 # Define dx.map settings. 3068 dx_inc = 2 3069 dx_inc_sides = dx_inc / 2 3070 3071 dx_params = ['dw', 'pA', 'kex'] 3072 dx_point_clustered_min = [cur_spin.dw, cur_spin.pA, cur_spin.kex] 3073 3074 print("Params for dx map is") 3075 print(dx_params) 3076 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3077 print(dx_point_clustered_min) 3078 3079 # Define file_names. 3080 cur_model = 'CR72' 3081 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str) 3082 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str) 3083 3084 # Step-size of parameter is 10 % 3085 param_delta = 0.1 3086 3087 # Determine bounds for lower and upper 3088 lower = [] 3089 upper = [] 3090 for i, param_val in enumerate(dx_point_clustered_min): 3091 param = dx_params[i] 3092 step_val = param_delta * param_val 3093 step_length = step_val * dx_inc_sides 3094 3095 # Calculate value 3096 low_val = param_val - step_length 3097 lower.append(low_val) 3098 3099 upp_val = param_val + step_length 3100 upper.append(upp_val) 3101 3102 print("For param %s, lower=%3.3f, upper=%3.3f, step_value=%3.3f, steps=%i, centered at=%3.3f"% (param, low_val, upp_val, step_val, dx_inc, param_val)) 3103 3104 # If the number of increments are 2, there will be 3 point calculations per parameter. 3105 # Since we have ordered the lower and upper limits on sides of the parameter, the middle index should give us the expected global value. 3106 dx_param_indexes = dx_inc + 1 3107 dx_point_index = dx_inc_sides + 1 3108 3109 # Find the line number. 3110 line = 1 3111 for i in range(1, dx_param_indexes + 1): 3112 for j in range(1, dx_param_indexes + 1): 3113 for k in range(1, dx_param_indexes + 1): 3114 if i == dx_point_index and j == dx_point_index and k == dx_point_index: 3115 line_chi2 = line 3116 # Add to line counter. 3117 line += 1 3118 3119 # Define temporary folder. 3120 result_dir = self.tmpdir 3121 3122 # For testing. 3123 #result_dir = None 3124 #lower = None 3125 #upper = None 3126 #self.interpreter.relax_disp.cluster(cluster_id='free spins', spin_id=cur_spin_id) 3127 3128 3129 # Then do the map. 3130 self.interpreter.dx.map(params=dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=dx_inc, lower=lower, upper=upper, axis_incs=10, file_prefix=file_name_map, dir=result_dir, point=dx_point_clustered_min, point_file=file_name_point) 3131 3132 # Print where to locate values. 3133 nr_chi2_val = dx_param_indexes**3 3134 print("Nr of chi2 calculations are=%i"%nr_chi2_val) 3135 print("Global chi2=%3.3f, Calc_chi=%3.3f, map_line_chi2=%i" % (pre_chi2, calc_chi2, line_chi2) ) 3136 3137 ## Check for file creation 3138 # Set filepaths. 3139 map_name = get_file_path(file_name=file_name_map, dir=result_dir) 3140 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir) 3141 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir) 3142 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir) 3143 3144 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir) 3145 point_point = get_file_path(file_name=file_name_point, dir=result_dir) 3146 3147 # Test the files exists. 3148 self.assert_(access(map_cfg, F_OK)) 3149 self.assert_(access(map_net, F_OK)) 3150 self.assert_(access(map_general, F_OK)) 3151 self.assert_(access(point_general, F_OK)) 3152 self.assert_(access(point_point, F_OK)) 3153 3154 # Open the file, and assert the chi2 value is as expected. 3155 get_data = extract_data(file=map_name) 3156 3157 # Extract line 0, column 0. 3158 test = float(get_data[line_chi2-1][0]) 3159 3160 # Assert. 3161 self.assertAlmostEqual(test, pre_chi2, 6)
3162 3163
3165 """Test making dx_map for residues under clustered calculation, and the creation of the parameter file. 3166 3167 U{Task #7860<https://gna.org/task/index.php?7860>} : When dx_map is issued, create a parameter file which maps parameters to chi2 value. 3168 3169 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 3170 """ 3171 3172 # Define path to data 3173 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'surface_chi2_clustered_fitting' 3174 3175 # Read data. 3176 self.interpreter.results.read(prev_data_path + sep + 'coMDD_-_TSMFK01_-_min_-_32_-_free_spins.bz2') 3177 3178 # Get residue of interest. 3179 cur_spin_id = ":%i@%s"%(65, 'N') 3180 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_') 3181 3182 # Get the spin container. 3183 cur_spin = return_spin(cur_spin_id) 3184 3185 # Get the chi2 value 3186 pre_chi2 = cur_spin.chi2 3187 3188 # Then do a local minimisation. 3189 #self.interpreter.select.spin(":%i@%s"%(2, 'N')) 3190 self.interpreter.minimise.calculate() 3191 3192 # Get the chi2 value after calculation. 3193 calc_chi2 = cur_spin.chi2 3194 3195 # Assert calculation is equal. 3196 self.assertAlmostEqual(pre_chi2, calc_chi2) 3197 3198 # Define dx.map settings. 3199 dx_inc = 2 3200 dx_params = ['dw', 'k_AB', 'r2a'] 3201 dx_point_clustered_min = [cur_spin.dw, cur_spin.k_AB, cur_spin.r2a['SQ CPMG - 499.86214000 MHz']] 3202 3203 print("Params for dx map is") 3204 print(dx_params) 3205 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3206 print(dx_point_clustered_min) 3207 3208 # Define file_names. 3209 cur_model = 'TSMFK01' 3210 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str) 3211 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str) 3212 3213 # Determine bounds for lower and upper 3214 lower = [dx_point_clustered_min[0], dx_point_clustered_min[1], dx_point_clustered_min[2]] 3215 upper = [19.0, 2.4, 9.5] 3216 3217 # Define temporary folder. 3218 result_dir = self.tmpdir 3219 3220 # For testing. 3221 #result_dir = None 3222 #self.interpreter.relax_disp.cluster(cluster_id='free spins', spin_id=cur_spin_id) 3223 3224 # Then do the map. 3225 self.interpreter.dx.map(params=dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=dx_inc, lower=lower, upper=upper, axis_incs=10, file_prefix=file_name_map, dir=result_dir, point=dx_point_clustered_min, point_file=file_name_point, create_par_file=True) 3226 3227 # Print where to locate values. 3228 nr_chi2_val = (dx_inc + 1)**3 3229 print("Nr of chi2 calculations are=%i"%nr_chi2_val) 3230 print("Global chi2=%3.3f, Calc_chi=%3.3f" % (pre_chi2, calc_chi2) ) 3231 3232 ## Check for file creation 3233 # Set filepaths. 3234 map_name = get_file_path(file_name=file_name_map, dir=result_dir) 3235 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir) 3236 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir) 3237 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir) 3238 map_par = get_file_path(file_name=file_name_map+".par", dir=result_dir) 3239 3240 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir) 3241 point_point = get_file_path(file_name=file_name_point, dir=result_dir) 3242 3243 # Test the files exists. 3244 self.assert_(access(map_cfg, F_OK)) 3245 self.assert_(access(map_net, F_OK)) 3246 self.assert_(access(map_general, F_OK)) 3247 self.assert_(access(map_par, F_OK)) 3248 self.assert_(access(point_general, F_OK)) 3249 self.assert_(access(point_point, F_OK)) 3250 3251 print("\nParams for dx map is") 3252 print(dx_params) 3253 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3254 print(dx_point_clustered_min, "\n") 3255 3256 # Open the parameter chi2 file, and assert the chi2 value in the sorted parameter file is not lower that than the global minimisation. 3257 get_data = extract_data(file=map_par) 3258 3259 # Extract line 1, column 9. 3260 test = float(get_data[1][9]) 3261 3262 # Print data if map contain a lower value than the global minimised value. 3263 if test < pre_chi2: 3264 print("\nInitial clustered minimised chi2 value is=%3.3f, whereby the minimum map value is=%3.3f\n" % (pre_chi2, test)) 3265 for line in get_data: 3266 print(line)
3267 3268 # Assert that the initial global chi2 is lower than the map value. 3269 3270 # The following test was taken out, since this a particular interesting case. 3271 # There exist a double minimum, where relax has not found the global minimum. 3272 # This is due to not grid searching for R2A, but using the minimum 3273 #self.assert_(pre_chi2 < test) 3274 3275
3276 - def test_estimate_r2eff_err(self):
3277 """Test the user function for estimating R2eff errors from exponential curve fitting. 3278 3279 This follows Task 7822. 3280 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3281 3282 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3283 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3284 """ 3285 3286 # Cluster residues 3287 cluster_ids = [ 3288 ":13@N", 3289 ":15@N", 3290 ":16@N", 3291 ":25@N", 3292 ":26@N", 3293 ":28@N", 3294 ":39@N", 3295 ":40@N", 3296 ":41@N", 3297 ":43@N", 3298 ":44@N", 3299 ":45@N", 3300 ":49@N", 3301 ":52@N", 3302 ":53@N"] 3303 3304 # Load the data. 3305 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3306 3307 # The dispersion models. 3308 MODELS = [MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3309 3310 # The grid search size (the number of increments per dimension). 3311 GRID_INC = None 3312 3313 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3314 MC_NUM = 3 3315 3316 # Model selection technique. 3317 MODSEL = 'AIC' 3318 3319 # Execute the auto-analysis (fast). 3320 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3321 OPT_FUNC_TOL = 1e-25 3322 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3323 OPT_MAX_ITERATIONS = 10000000 3324 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3325 3326 result_dir_name = ds.tmpdir 3327 3328 # Make all spins free 3329 for curspin in cluster_ids: 3330 self.interpreter.relax_disp.cluster('free spins', curspin) 3331 # Shut them down 3332 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 3333 3334 # Select only a subset of spins for global fitting 3335 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3336 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3337 3338 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3339 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3340 3341 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3342 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3343 3344 # Set the model. 3345 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3346 3347 # Check if intensity errors have already been calculated. 3348 check_intensity_errors() 3349 3350 # Do a grid search. 3351 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 3352 3353 # Minimise. 3354 self.interpreter.minimise.execute(min_algor='Newton', constraints=False, verbosity=1) 3355 3356 # Estimate R2eff errors. 3357 self.interpreter.relax_disp.r2eff_err_estimate() 3358 3359 r1_fit = True 3360 3361 # Run the analysis. 3362 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, r1_fit=r1_fit) 3363 3364 # Verify the data. 3365 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3366 3367
3369 """Test the user function for estimating R2eff errors from exponential curve fitting, via the auto_analyses menu. 3370 3371 This follows Task 7822. 3372 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3373 3374 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3375 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3376 """ 3377 3378 # Cluster residues 3379 cluster_ids = [ 3380 ":13@N", 3381 ":15@N", 3382 ":16@N", 3383 ":25@N", 3384 ":26@N", 3385 ":28@N", 3386 ":39@N", 3387 ":40@N", 3388 ":41@N", 3389 ":43@N", 3390 ":44@N", 3391 ":45@N", 3392 ":49@N", 3393 ":52@N", 3394 ":53@N"] 3395 3396 # Load the data. 3397 #self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3398 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 3399 3400 # Set pipe name, bundle and type. 3401 pipe_name = 'base pipe' 3402 pipe_bundle = 'relax_disp' 3403 pipe_type = 'relax_disp' 3404 3405 # Create the data pipe. 3406 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 3407 3408 file = data_path + '1_setup_r1rho_GUI.py' 3409 self.interpreter.script(file=file, dir=None) 3410 3411 # The dispersion models. 3412 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3413 3414 # The grid search size (the number of increments per dimension). 3415 GRID_INC = None 3416 3417 # The number of Monte Carlo simulations to be used for error analysis for exponential curve fitting of R2eff. 3418 # When set to minus 1, estimation of the errors will be extracted from the covariance matrix. 3419 # This is HIGHLY likely to be wrong, but can be used in an initial test fase. 3420 EXP_MC_NUM = -1 3421 3422 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3423 MC_NUM = 3 3424 3425 # Model selection technique. 3426 MODSEL = 'AIC' 3427 3428 # Execute the auto-analysis (fast). 3429 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3430 OPT_FUNC_TOL = 1e-25 3431 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3432 OPT_MAX_ITERATIONS = 10000000 3433 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3434 3435 # Make all spins free 3436 #for curspin in cluster_ids: 3437 # self.interpreter.relax_disp.cluster('free spins', curspin) 3438 # # Shut them down 3439 # self.interpreter.deselect.spin(spin_id=curspin, boolean='OR', change_all=False) 3440 3441 # Make all spins free 3442 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 3443 3444 # Select only a subset of spins for global fitting 3445 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3446 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3447 3448 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3449 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3450 3451 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3452 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3453 3454 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3455 print(spin_id) 3456 3457 result_dir_name = self.tmpdir 3458 r1_fit = True 3459 3460 # Run the analysis. 3461 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=EXP_MC_NUM, modsel=MODSEL, r1_fit=r1_fit) 3462 3463 # Verify the data. 3464 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3465 3466
3468 """Test the user function for estimating R2eff and associated errors for exponential curve fitting with different methods. 3469 This is compared with a run where erros are estimated by 2000 Monte Carlo simulations. 3470 3471 This follows Task 7822. 3472 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3473 3474 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3475 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3476 3477 NOTE: The difference in the methods was due to a bug in relax! 3478 U{bug #22554<https://gna.org/bugs/index.php?22554>}. The distribution of intensity with errors in Monte-Carlo simulations are markedly more narrow than expected. 3479 3480 This dataset is old, and includes 2000 Monte-Carlo simulations, which is performed wrong. 3481 """ 3482 3483 # Define data path. 3484 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff" 3485 3486 # Create pipe. 3487 self.interpreter.pipe.create('MC_2000', 'relax_disp') 3488 3489 # Read results for 2000 MC simulations. 3490 self.interpreter.results.read(prev_data_path + sep + 'results') 3491 3492 # Start dic. 3493 my_dic = {} 3494 param_key_list = [] 3495 3496 # Do boot strapping ? 3497 do_boot = True 3498 if do_boot: 3499 min_algor = 'Newton' 3500 min_options = () 3501 sim_boot = 200 3502 scaling_list = [1.0, 1.0] 3503 3504 # First check sim values. 3505 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3506 # Add key to dic. 3507 my_dic[spin_id] = {} 3508 3509 # Loop over sim. 3510 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3511 # Loop over all exp type. 3512 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3513 # Generate the param_key. 3514 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3515 r2eff_sim_point = r2eff_sim[param_key] 3516 i0_sim_point = cur_spin.r2eff_sim[i][param_key] 3517 3518 # Assert point are higher than 0.0. 3519 #point_info = "r2eff=%3.2f i0=%3.2f, at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f, at sim index %i." % (r2eff_sim_point, i0_sim_point, frq/1E6, offset, point, i) 3520 #print(point_info) 3521 self.assert_(r2eff_sim_point > 0.0) 3522 self.assert_(i0_sim_point > 0.0) 3523 3524 # Get the data. 3525 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3526 # Generate spin string. 3527 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3528 3529 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3530 # Generate the param_key. 3531 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3532 3533 # Loop over all sim, and collect data. 3534 r2eff_sim_l = [] 3535 i0_sim_l = [] 3536 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3537 i0_sim = cur_spin.i0_sim[i] 3538 3539 r2eff_sim_i = r2eff_sim[param_key] 3540 r2eff_sim_l.append(r2eff_sim_i) 3541 i0_sim_i = i0_sim[param_key] 3542 i0_sim_l.append(i0_sim_i) 3543 3544 # Take the standard deviation of all values. 3545 r2eff_sim_err = std(asarray(r2eff_sim_l), ddof=1) 3546 i0_sim_err = std(asarray(i0_sim_l), ddof=1) 3547 3548 # Append key. 3549 param_key_list.append(param_key) 3550 3551 # Add key to dic. 3552 my_dic[spin_id][param_key] = {} 3553 3554 # Get the value. 3555 r2eff = getattr(cur_spin, 'r2eff')[param_key] 3556 r2eff_err = getattr(cur_spin, 'r2eff_err')[param_key] 3557 i0 = getattr(cur_spin, 'i0')[param_key] 3558 i0_err = getattr(cur_spin, 'i0_err')[param_key] 3559 3560 # Save to dic. 3561 my_dic[spin_id][param_key]['r2eff'] = r2eff 3562 my_dic[spin_id][param_key]['r2eff_err'] = r2eff_err 3563 my_dic[spin_id][param_key]['i0'] = i0 3564 my_dic[spin_id][param_key]['i0_err'] = i0_err 3565 my_dic[spin_id][param_key]['r2eff_err_sim'] = r2eff_sim_err 3566 my_dic[spin_id][param_key]['i0_err_sim'] = i0_sim_err 3567 3568 # Assert values are equal 3569 self.assertAlmostEqual(r2eff_sim_err, r2eff_err) 3570 self.assertAlmostEqual(i0_sim_err, i0_err) 3571 3572 if do_boot: 3573 values = [] 3574 errors = [] 3575 times = [] 3576 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 3577 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 3578 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 3579 times.append(time) 3580 3581 # Convert to numpy array. 3582 values = asarray(values) 3583 errors = asarray(errors) 3584 times = asarray(times) 3585 3586 R_m_sim_l = [] 3587 I0_m_sim_l = [] 3588 for j in range(sim_boot): 3589 if j in range(0, 100000, 100): 3590 print("Simulation %i"%j) 3591 # Start minimisation. 3592 3593 # Produce errors 3594 I_err = [] 3595 for j, error in enumerate(errors): 3596 I_error = gauss(values[j], error) 3597 I_err.append(I_error) 3598 # Convert to numpy array. 3599 I_err = asarray(I_err) 3600 3601 x0 = [r2eff, i0] 3602 setup(num_params=len(x0), num_times=len(times), values=I_err, sd=errors, relax_times=times, scaling_matrix=scaling_list) 3603 3604 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=func, dfunc=dfunc, d2func=d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, full_output=True, print_flag=0) 3605 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 3606 R_m_sim_l.append(R_m_sim_j) 3607 I0_m_sim_l.append(I0_m_sim_j) 3608 3609 # Get stats on distribution. 3610 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 3611 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 3612 my_dic[spin_id][param_key]['r2eff_err_boot'] = sigma_R_sim 3613 my_dic[spin_id][param_key]['i0_err_boot'] = sigma_I0_sim 3614 3615 3616 # A new data pipe. 3617 self.interpreter.pipe.copy(pipe_from='MC_2000', pipe_to='r2eff_est') 3618 self.interpreter.pipe.switch(pipe_name='r2eff_est') 3619 3620 # Delete old errors. 3621 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3622 delattr(cur_spin, 'r2eff_err') 3623 delattr(cur_spin, 'i0_err') 3624 3625 # Set the model. 3626 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3627 3628 # Estimate R2eff and errors. 3629 self.interpreter.relax_disp.r2eff_err_estimate(verbosity=0) 3630 3631 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3632 # Generate spin string. 3633 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3634 3635 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3636 # Generate the param_key. 3637 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3638 3639 # Get the value. 3640 r2eff_est = getattr(cur_spin, 'r2eff')[param_key] 3641 r2eff_err_est = getattr(cur_spin, 'r2eff_err')[param_key] 3642 i0_est = getattr(cur_spin, 'i0')[param_key] 3643 i0_err_est = getattr(cur_spin, 'i0_err')[param_key] 3644 3645 # Get from dic. 3646 r2eff = my_dic[spin_id][param_key]['r2eff'] 3647 r2eff_err = my_dic[spin_id][param_key]['r2eff_err'] 3648 i0 = my_dic[spin_id][param_key]['i0'] 3649 i0_err = my_dic[spin_id][param_key]['i0_err'] 3650 r2eff_sim_err = my_dic[spin_id][param_key]['r2eff_err_sim'] 3651 i0_sim_err = my_dic[spin_id][param_key]['i0_err_sim'] 3652 3653 if do_boot: 3654 r2eff_boot_err = my_dic[spin_id][param_key]['r2eff_err_boot'] 3655 i0_boot_err = my_dic[spin_id][param_key]['i0_err_boot'] 3656 else: 3657 r2eff_boot_err = 0.0 3658 i0_boot_err = 0.0 3659 3660 print("%s at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f." % (exp_type, frq/1E6, offset, point) ) 3661 print("r2eff=%3.3f/%3.3f r2eff_err=%3.4f/%3.4f/%3.4f/%3.4f" % (r2eff, r2eff_est, r2eff_err, r2eff_err_est, r2eff_sim_err, r2eff_boot_err) ), 3662 print("i0=%3.3f/%3.3f i0_err=%3.4f/%3.4f/%3.4f/%3.4f\n" % (i0, i0_est, i0_err, i0_err_est, i0_sim_err, i0_boot_err) ) 3663 3664 3665 # Now do it manually. 3666 estimate_r2eff(method='scipy.optimize.leastsq') 3667 3668 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=False) 3669 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=True) 3670 3671 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=False) 3672 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=True) 3673 3674 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=False) 3675 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=True) 3676 3677 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=False) 3678 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=True) 3679 3680 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=False) 3681 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=True)
3682 3683 3684
3685 - def test_exp_fit(self):
3686 """Test the relaxation dispersion 'exp_fit' model curve fitting.""" 3687 3688 # Execute the script. 3689 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'exp_fit.py') 3690 3691 # The original exponential curve parameters. 3692 res_data = [ 3693 [15., 10., 20000., 25000.], 3694 [12., 11., 50000., 51000.], 3695 [17., 9., 100000., 96000.] 3696 ] 3697 3698 # List of parameters which do not belong to the model. 3699 blacklist = ['cpmg_frqs', 'r2', 'rex', 'kex', 'r2a', 'k_AB', 'dw'] 3700 3701 # Checks for each residue. 3702 for i in range(len(res_data)): 3703 # Printout. 3704 print("\nResidue number %s." % (i+1)) 3705 3706 # Check the fitted parameters. 3707 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_1000.000'], res_data[i][0], places=2) 3708 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_2000.000'], res_data[i][1], places=2) 3709 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_1000.000']/10000, res_data[i][2]/10000, places=3) 3710 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_2000.000']/10000, res_data[i][3]/10000, places=3) 3711 3712 # Check the simulation errors. 3713 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_1000.000'] < 5.0) 3714 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_2000.000'] < 5.0) 3715 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_1000.000']/10000 < 5.0) 3716 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_2000.000']/10000 < 5.0) 3717 3718 # Check that certain parameters are not present. 3719 for param in blacklist: 3720 print("\tChecking for the absence of the '%s' parameter." % param) 3721 self.assert_(not hasattr(cdp.mol[0].res[i].spin[0], param)) 3722 3723 # Check the clustering information. 3724 self.assert_(hasattr(cdp, 'clustering')) 3725 keys = ['free spins', 'cluster'] 3726 for key in keys: 3727 self.assert_(key in cdp.clustering) 3728 self.assert_('test' not in cdp.clustering) 3729 self.assertEqual(cdp.clustering['free spins'], [':2@N']) 3730 self.assertEqual(cdp.clustering['cluster'], [':1@N', ':3@N'])
3731 3732
3733 - def test_finite_value(self):
3734 """Test return from C code, when parameters are wrong. This can happen, if minfx takes a wrong step.""" 3735 3736 times = array([ 0.7, 1., 0.8, 0.4, 0.9]) 3737 I = array([ 476.76174875, 372.43328777, 454.20339981, 656.87936253, 419.16726341]) 3738 errors = array([ 9.48032653, 11.34093541, 9.35149017, 10.84867928, 12.17590736]) 3739 3740 scaling_list = [1.0, 1.0] 3741 setup(num_params=2, num_times=len(times), values=I, sd=errors, relax_times=times, scaling_matrix=scaling_list) 3742 3743 R = - 500. 3744 I0 = 1000. 3745 params = [R, I0] 3746 3747 chi2 = func(params) 3748 3749 print("The chi2 value returned from C-code for R=%3.2f and I0=%3.2f, then chi2=%3.2f"%(R, I0, chi2)) 3750 self.assertNotEqual(chi2, inf)
3751 3752
3753 - def test_hansen_catia_input(self):
3754 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CATIA. 3755 3756 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3757 """ 3758 3759 # Load the R2eff results file. 3760 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 3761 self.interpreter.results.read(file_name) 3762 self.interpreter.deselect.spin(':4') 3763 3764 # The spin isotopes. 3765 self.interpreter.spin.isotope("15N") 3766 3767 # Generate the input files. 3768 self.interpreter.relax_disp.catia_input(dir=ds.tmpdir, force=True) 3769 3770 # Check the r2eff set files. 3771 print("\nChecking the R2eff input set files.") 3772 files = ['data_set_500.inp', 'data_set_500.inp'] 3773 for file in files: 3774 self.assert_(access(ds.tmpdir+sep+file, F_OK)) 3775 data_set_500 = [ 3776 "ID=500\n", 3777 "Sfrq = 500\n", 3778 "Temperature = 0.0\n", 3779 "Nucleus = N15\n", 3780 "Couplednucleus = H1\n", 3781 "Time_equil = 0.0\n", 3782 "Pwx_cp = 0.0\n", 3783 "Taub = 0.0\n", 3784 "Time_T2 = 0.03\n", 3785 "Xcar = 0.0\n", 3786 "Seqfil = CW_CPMG\n", 3787 "Minerror = (2.%;0.5/s)\n", 3788 "Basis = (Iph_7)\n", 3789 "Format = (0;1;2)\n", 3790 "DataDirectory = /tmp/tmpNjOGNG/input_r2eff\n", 3791 "Data = (\n", 3792 " [70N;spin_70_N_500.cpmg];\n", 3793 " [71N;spin_71_N_500.cpmg];\n", 3794 ")\n", 3795 ] 3796 file = open(ds.tmpdir+sep+files[0]) 3797 lines = file.readlines() 3798 file.close() 3799 for i in range(len(data_set_500)): 3800 # Skip the data directory, as this is a random file name. 3801 if i == 14: 3802 continue 3803 3804 self.assertEqual(data_set_500[i], lines[i]) 3805 3806 # Check the r2eff files. 3807 print("\nChecking the R2eff input files.") 3808 files = ['spin_70_N_500.cpmg', 'spin_70_N_800.cpmg', 'spin_71_N_500.cpmg', 'spin_71_N_800.cpmg'] 3809 for file in files: 3810 self.assert_(access(ds.tmpdir+sep+'input_r2eff'+sep+file, F_OK)) 3811 spin_70_N_500 = [ 3812 "# nu_cpmg(Hz) R2(1/s) Esd(R2)\n", 3813 " 66.666600000000003 16.045540885533605 0.310924686180635\n", 3814 " 133.333300000000008 14.877924861181727 0.303217270671013\n", 3815 " 200.000000000000000 14.357820247260586 0.299894424543361\n", 3816 " 266.666600000000017 12.664494620416516 0.289532060485796\n", 3817 " 333.333300000000008 12.363204802467891 0.287759631749322\n", 3818 " 400.000000000000000 11.092532381134513 0.280514035409862\n", 3819 " 466.666600000000017 10.566090057649893 0.277618625949722\n", 3820 " 533.333300000000008 9.805806894657803 0.273544382200754\n", 3821 " 600.000000000000000 9.564300692201730 0.272276309984954\n", 3822 " 666.666600000000017 9.015633750407980 0.269441511838159\n", 3823 " 733.333300000000008 8.607764958055581 0.267375134391053\n", 3824 " 800.000000000000000 8.279997179221338 0.265739551961997\n", 3825 " 866.666600000000017 8.474535940963516 0.266707642726566\n", 3826 " 933.333300000000008 8.158972897365194 0.265141210539941\n", 3827 "1000.000000000000000 7.988630509501972 0.264304105548559\n", 3828 ] 3829 file = open(ds.tmpdir+sep+'input_r2eff'+sep+files[0]) 3830 lines = file.readlines() 3831 file.close() 3832 for i in range(len(lines)): 3833 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 3834 for i in range(len(spin_70_N_500)): 3835 self.assertEqual(spin_70_N_500[i], lines[i]) 3836 3837 # Check the main file. 3838 print("\nChecking the main CATIA execution file.") 3839 main_file = [ 3840 "ReadDataset(data_set_500.inp)\n", 3841 "ReadDataset(data_set_800.inp)\n", 3842 "ReadParam_Global(ParamGlobal.inp)\n", 3843 "ReadParam_Local(ParamSet1.inp)\n", 3844 "\n", 3845 "FreeLocalParam(all;Omega;false)\n", 3846 "FreeLocalParam(all;R1iph_500;false)\n", 3847 "FreeLocalParam(all;R1iph_800;false)\n", 3848 "\n", 3849 "Minimize(print=y;tol=1e-25;maxiter=10000000)\n", 3850 "\n", 3851 "PrintParam(output/GlobalParam.fit;global)\n", 3852 "PrintParam(output/DeltaOmega.fit;DeltaO)\n", 3853 "PrintData(output/)\n", 3854 "\n", 3855 "ChiSq(all;all)\n", 3856 "exit(0)\n" 3857 ] 3858 file = open("%s%sFit.catia" % (ds.tmpdir, sep)) 3859 lines = file.readlines() 3860 file.close() 3861 for i in range(len(main_file)): 3862 self.assertEqual(main_file[i], lines[i])
3863 3864
3866 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 3867 3868 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3869 """ 3870 3871 # Set the model. 3872 ds.models = [ 3873 MODEL_NOREX, 3874 MODEL_LM63, 3875 MODEL_CR72, 3876 MODEL_IT99 3877 ] 3878 3879 # Execute the script. 3880 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 3881 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 3882 3883 # The R20 keys. 3884 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 3885 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 3886 3887 # The 'No Rex' model checks. 3888 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 3889 spin70 = return_spin(":70") 3890 spin71 = return_spin(":71") 3891 print("\n\nOptimised parameters:\n") 3892 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3893 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3894 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3895 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3896 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 3897 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 3898 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 3899 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 3900 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 3901 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 3902 3903 # The 'LM63' model checks. 3904 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 3905 spin70 = return_spin(":70") 3906 spin71 = return_spin(":71") 3907 print("\n\nOptimised parameters:\n") 3908 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3909 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3910 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3911 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 3912 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3913 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3914 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 3915 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 3916 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 3917 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 3918 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 3919 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 3920 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 3921 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 3922 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 3923 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 3924 3925 # The 'CR72' model checks. 3926 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 3927 spin70 = return_spin(":70") 3928 spin71 = return_spin(":71") 3929 print("\n\nOptimised parameters:\n") 3930 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3931 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3932 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3933 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 3934 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 3935 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3936 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3937 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 3938 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 3939 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 3940 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 3941 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 3942 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 3943 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 3944 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 3945 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 3946 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 3947 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 3948 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3)
3949 3950
3952 """Test of the numeric model only dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 3953 3954 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3955 """ 3956 3957 # Set the model and numeric flag. 3958 ds.models = [ 3959 MODEL_NOREX, 3960 MODEL_CR72, 3961 MODEL_NS_CPMG_2SITE_EXPANDED 3962 ] 3963 ds.numeric_only = True 3964 3965 # Execute the script. 3966 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 3967 3968 # The R20 keys. 3969 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 3970 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 3971 3972 # The 'No Rex' model checks. 3973 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 3974 spin70 = return_spin(":70") 3975 spin71 = return_spin(":71") 3976 print("\n\nOptimised parameters:\n") 3977 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3978 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3979 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3980 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3981 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 3982 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 3983 self.assertAlmostEqual(spin70.chi2/10000, 8973.84810025761/10000, 3) 3984 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 3985 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 3986 self.assertAlmostEqual(spin71.chi2/10000, 3908.00127830003/10000, 3) 3987 3988 # The 'CR72' model checks. 3989 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 3990 spin70 = return_spin(":70") 3991 spin71 = return_spin(":71") 3992 print("\n\nOptimised parameters:\n") 3993 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3994 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3995 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3996 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 3997 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 3998 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3999 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4000 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4001 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4002 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4003 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4004 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4005 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4006 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 4007 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 4008 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 4009 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 4010 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 4011 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3) 4012 4013 # The 'NS CPMG 2-site expanded' model checks. 4014 self.interpreter.pipe.switch(pipe_name='NS CPMG 2-site expanded - relax_disp') 4015 spin70 = return_spin(":70") 4016 spin71 = return_spin(":71") 4017 print("\n\nOptimised parameters:\n") 4018 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4019 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4020 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4021 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4022 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4023 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4024 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4025 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95815351460902, 3) 4026 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39649535771294, 3) 4027 self.assertAlmostEqual(spin70.pA, 0.989701014493195, 3) 4028 self.assertAlmostEqual(spin70.dw, 5.67314464776128, 3) 4029 self.assertAlmostEqual(spin70.kex/10000, 1713.65380495429/10000, 3) 4030 self.assertAlmostEqual(spin70.chi2, 52.5106880917473, 3) 4031 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99889337382435, 3) 4032 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89822887466673, 3) 4033 self.assertAlmostEqual(spin71.pA, 0.986709050819695, 3) 4034 self.assertAlmostEqual(spin71.dw, 2.09238266766502, 2) 4035 self.assertAlmostEqual(spin71.kex/10000, 2438.27019901422/10000, 3) 4036 self.assertAlmostEqual(spin71.chi2, 15.1644906963987, 3) 4037 4038 # The final data pipe checks. 4039 self.interpreter.pipe.switch(pipe_name='final - relax_disp') 4040 spin70 = return_spin(":70") 4041 spin71 = return_spin(":71") 4042 self.assertEqual(spin70.model, 'NS CPMG 2-site expanded') 4043 self.assertEqual(spin71.model, 'NS CPMG 2-site expanded')
4044 4045
4047 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data (using the R2eff data directly instead of peak intensities). 4048 4049 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4050 """ 4051 4052 # Set the model. 4053 ds.models = [ 4054 MODEL_NOREX, 4055 MODEL_LM63, 4056 MODEL_CR72, 4057 MODEL_IT99 4058 ] 4059 4060 # Execute the script. 4061 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_r2eff_data.py') 4062 self.interpreter.state.save('analysis_r2eff', dir=ds.tmpdir, force=True) 4063 4064 # The R20 keys. 4065 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4066 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4067 4068 # The 'No Rex' model checks. 4069 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4070 spin70 = return_spin(":70") 4071 spin71 = return_spin(":71") 4072 print("\n\nOptimised parameters:\n") 4073 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4074 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4075 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4076 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4077 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 4078 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 4079 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 4080 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4081 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4082 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 4083 4084 # The 'LM63' model checks. 4085 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 4086 spin70 = return_spin(":70") 4087 spin71 = return_spin(":71") 4088 print("\n\nOptimised parameters:\n") 4089 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4090 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4091 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4092 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4093 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4094 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4095 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 4096 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 4097 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 4098 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 4099 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 4100 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 4101 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 4102 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 4103 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 4104 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 4105 4106 # The 'CR72' model checks. 4107 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4108 spin70 = return_spin(":70") 4109 spin71 = return_spin(":71") 4110 print("\n\nOptimised parameters:\n") 4111 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4112 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4113 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4114 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4115 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4116 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4117 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4118 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4119 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4120 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4121 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4122 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4123 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4124 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00317154730225, 3) 4125 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797713541, 3) 4126 self.assertAlmostEqual(spin71.pA, 0.985922406429147, 3) 4127 self.assertAlmostEqual(spin71.dw, 2.00500965887772, 2) 4128 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579804/10000, 3) 4129 self.assertAlmostEqual(spin71.chi2, 15.6595374288635, 3)
4130 4131
4133 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data with parts missing. 4134 4135 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4136 """ 4137 4138 # Set the model. 4139 ds.models = [ 4140 MODEL_R2EFF, 4141 MODEL_NOREX, 4142 MODEL_CR72, 4143 MODEL_NS_CPMG_2SITE_EXPANDED 4144 ] 4145 4146 # Execute the script. 4147 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data_missing.py') 4148 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 4149 4150 # The R20 keys. 4151 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4152 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4153 4154 # The 'No Rex' model checks. 4155 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4156 spin4 = return_spin(":4") 4157 spin70 = return_spin(":70") 4158 spin71 = return_spin(":71") 4159 print("\n\nOptimised parameters:\n") 4160 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 4161 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 4162 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 4163 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 4164 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463084515171, 3) 4165 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63220784651911, 3) 4166 self.assertAlmostEqual(spin4.chi2, 26.7356700694891, 3) 4167 self.assertAlmostEqual(spin70.r2[r20_key1], 10.534285641325, 3) 4168 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112794857068, 3) 4169 self.assertAlmostEqual(spin70.chi2, 8973.84809774722, 3) 4170 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83136858890037, 3) 4171 self.assertAlmostEqual(spin71.chi2, 182.60081909193, 3) 4172 4173 # The 'CR72' model checks. 4174 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4175 spin4 = return_spin(":4") 4176 spin70 = return_spin(":70") 4177 spin71 = return_spin(":71") 4178 print("\n\nOptimised parameters:\n") 4179 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 4180 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 4181 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 4182 print("%-20s %20.15g %20.15g %20.15g" % ("pA", spin4.pA, spin70.pA, spin71.pA)) 4183 print("%-20s %20.15g %20.15g %20.15g" % ("dw", spin4.dw, spin70.dw, spin71.dw)) 4184 print("%-20s %20.15g %20.15g %20.15g" % ("kex", spin4.kex, spin70.kex, spin71.kex)) 4185 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 4186 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463650370664, 2) 4187 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63221675941434, 3) 4188 #self.assertAlmostEqual(spin4.pA, 0.818979078699935, 3) # As dw (and kex) is zero, this parameter is not stable. 4189 self.assertAlmostEqual(spin4.dw, 0.0, 2) 4190 self.assertAlmostEqual(spin4.kex/10000, 0.0, 3) 4191 self.assertAlmostEqual(spin4.chi2/100, 26.7356711142038/100, 3) 4192 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97268077496405, 3) 4193 self.assertAlmostEqual(spin70.r2[r20_key2], 9.41028133407727, 3) 4194 self.assertAlmostEqual(spin70.pA, 0.989856641885939, 3) 4195 self.assertAlmostEqual(spin70.dw, 5.60889911049405, 3) 4196 self.assertAlmostEqual(spin70.kex/10000, 1752.62025618632/10000, 3) 4197 self.assertAlmostEqual(spin70.chi2, 53.8382196964083, 3) 4198 self.assertAlmostEqual(spin71.r2[r20_key1], 4.98123328466942, 3) 4199 self.assertAlmostEqual(spin71.pA, 0.996607425484157, 3) 4200 self.assertAlmostEqual(spin71.dw, 4.34346257383825, 2) 4201 self.assertAlmostEqual(spin71.kex/10000, 1936.73197158804/10000, 3) 4202 self.assertAlmostEqual(spin71.chi2, 5.51703791653689, 3)
4203 4204
4206 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 dispersion model. 4207 4208 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4209 """ 4210 4211 # Base data setup. 4212 self.setup_hansen_cpmg_data(model='CR72') 4213 4214 # Alias the spins. 4215 spin70 = return_spin(":70") 4216 spin71 = return_spin(":71") 4217 4218 # The R20 keys. 4219 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4220 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4221 4222 # Set the initial parameter values. 4223 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4224 spin70.pA = 0.9 4225 spin70.dw = 6.0 4226 spin70.kex = 1500.0 4227 spin71.r2 = {r20_key1: 5, r20_key2: 9.0} 4228 spin71.pA = 0.9 4229 spin71.dw = 4.0 4230 spin71.kex = 1900.0 4231 4232 # Low precision optimisation. 4233 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4234 4235 # Printout. 4236 print("\n\nOptimised parameters:\n") 4237 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4238 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4239 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4240 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4241 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4242 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4243 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4244 4245 # Checks for residue :70. 4246 self.assertAlmostEqual(spin70.r2[r20_key1], 6.9724581325007, 4) 4247 self.assertAlmostEqual(spin70.r2[r20_key2], 9.40968331038162, 2) 4248 self.assertAlmostEqual(spin70.pA, 0.989856656702431, 4) 4249 self.assertAlmostEqual(spin70.dw, 5.60885879594746, 3) 4250 self.assertAlmostEqual(spin70.kex/1000, 1752.91052702273/1000, 3) 4251 self.assertAlmostEqual(spin70.chi2, 53.8382133597495, 4) 4252 4253 # Checks for residue :71. 4254 self.assertAlmostEqual(spin71.r2[r20_key1], 5.0030740940524, 4) 4255 self.assertAlmostEqual(spin71.pA, 0.985941082507823, 4) 4256 self.assertAlmostEqual(spin71.dw, 2.00640384113696, 4) 4257 self.assertAlmostEqual(spin71.kex/1000, 2480.79614442041/1000, 4) 4258 self.assertAlmostEqual(spin71.chi2, 15.6595388312451, 4) 4259 4260 # Test the conversion to k_AB from kex and pA. 4261 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4262 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4263 4264 # Test the conversion to k_BA from kex and pA. 4265 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4266 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4267 4268
4270 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 full dispersion model. 4271 4272 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4273 """ 4274 4275 # Base data setup. 4276 self.setup_hansen_cpmg_data(model='CR72 full') 4277 4278 # Alias the spins. 4279 spin70 = return_spin(":70") 4280 spin71 = return_spin(":71") 4281 4282 # The R20 keys. 4283 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4284 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4285 4286 # Set the initial parameter values. 4287 spin70.r2a = {r20_key1: 7.0, r20_key2: 9.0} 4288 spin70.r2b = {r20_key1: 7.0, r20_key2: 9.0} 4289 spin70.pA = 0.9 4290 spin70.dw = 6.0 4291 spin70.kex = 1500.0 4292 spin71.r2a = {r20_key1: 5.0, r20_key2: 9.0} 4293 spin71.r2b = {r20_key1: 5.0, r20_key2: 9.0} 4294 spin71.pA = 0.9 4295 spin71.dw = 4.0 4296 spin71.kex = 1900.0 4297 4298 # Low precision optimisation. 4299 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4300 4301 # Printout. 4302 print("\n\nOptimised parameters:\n") 4303 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4304 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4305 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4306 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4307 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4308 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4309 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4310 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4311 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4312 4313 # Checks for residue :70. 4314 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.87485258365614, 4) 4315 self.assertAlmostEqual(spin70.r2b[r20_key1], 1.26075839074614, 4) 4316 self.assertAlmostEqual(spin70.r2a[r20_key2], 8.79580446260797, 4) 4317 self.assertAlmostEqual(spin70.r2b[r20_key2], 51.188411562843, 4) 4318 self.assertAlmostEqual(spin70.pA, 0.989384178573802, 4) 4319 self.assertAlmostEqual(spin70.dw, 5.54738203723682, 4) 4320 self.assertAlmostEqual(spin70.kex/1000, 1831.4566463179/1000, 4) 4321 self.assertAlmostEqual(spin70.chi2, 50.450410782403, 4) 4322 4323 # Checks for residue :71. 4324 self.assertAlmostEqual(spin71.r2a[r20_key1], 5.04185695754972, 4) 4325 self.assertAlmostEqual(spin71.r2b[r20_key1], 1.62857899941921, 4) 4326 self.assertAlmostEqual(spin71.pA, 0.988832866751676, 4) 4327 self.assertAlmostEqual(spin71.dw, 2.24905251856265, 4) 4328 self.assertAlmostEqual(spin71.kex/1000, 2397.64122642946/1000, 4) 4329 self.assertAlmostEqual(spin71.chi2, 15.8586492923672, 4) 4330 4331 # Test the conversion to k_AB from kex and pA. 4332 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4333 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4334 4335 # Test the conversion to k_BA from kex and pA. 4336 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4337 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4338 4339
4341 """Optimisation of Dr. Flemming Hansen's CPMG data to the IT99 dispersion model. 4342 4343 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4344 """ 4345 4346 # Base data setup. 4347 self.setup_hansen_cpmg_data(model='IT99') 4348 4349 # Alias the spins. 4350 spin70 = return_spin(":70") 4351 spin71 = return_spin(":71") 4352 4353 # The R20 keys. 4354 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4355 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4356 4357 # Set the initial parameter values. 4358 spin70.r2 = {r20_key1: 8.8, r20_key2: 16.6} 4359 spin70.dw = 10.0 4360 spin70.pA = 0.5 4361 spin70.tex = 1000.09 4362 spin71.r2 = {r20_key1: 1.0, r20_key2: 1.0} 4363 spin71.dw = 10.0 4364 spin71.pA = 0.95 4365 spin71.tex = 0.1 4366 4367 # Low precision optimisation. 4368 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-10, grad_tol=None, max_iter=10000, constraints=True, scaling=True, verbosity=1) 4369 4370 # Printout. 4371 print("\n\nOptimised parameters:\n") 4372 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4373 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4374 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4375 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4376 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4377 print("%-20s %20.15g %20.15g" % ("tex", spin70.tex, spin71.tex)) 4378 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4379 4380 # Checks for residue :70. 4381 self.assertAlmostEqual(spin70.r2[r20_key1], 7.24471197811838, 4) 4382 self.assertAlmostEqual(spin70.r2[r20_key2], 10.0571040704729, 4) 4383 self.assertAlmostEqual(spin70.dw, 5.2116923222744, 4) 4384 self.assertAlmostEqual(spin70.pA, 0.990253627907212, 4) 4385 self.assertAlmostEqual(spin70.tex*1000, 0.000638394793480444*1000, 4) 4386 self.assertAlmostEqual(spin70.chi2, 93.5135798618747, 4) 4387 4388 # Checks for residue :71. 4389 self.assertAlmostEqual(spin71.r2[r20_key1], 5.05971235970214, 4) 4390 self.assertAlmostEqual(spin71.r2[r20_key2], 6.96641194493447, 4) 4391 self.assertAlmostEqual(spin71.dw, 0.435389946897141, 4) 4392 self.assertAlmostEqual(spin71.pA, 0.500000000213519, 3) 4393 self.assertAlmostEqual(spin71.tex*1000, 0.000372436400585538*1000, 4) 4394 self.assertAlmostEqual(spin71.chi2, 23.7895798801404, 4)
4395 4396
4398 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4399 4400 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4401 """ 4402 4403 # Base data setup. 4404 self.setup_hansen_cpmg_data(model='LM63') 4405 4406 # Alias the spins. 4407 spin70 = return_spin(":70") 4408 spin71 = return_spin(":71") 4409 4410 # The R20 keys. 4411 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4412 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4413 4414 # Set the initial parameter values. 4415 spin70.r2 = {r20_key1: 7.0, r20_key2: 7.0} 4416 spin70.phi_ex = 0.3 4417 spin70.kex = 5000.0 4418 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4419 spin71.phi_ex = 0.1 4420 spin71.kex = 2500.0 4421 4422 # Low precision optimisation. 4423 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1) 4424 4425 # Printout. 4426 print("\n\nOptimised parameters:\n") 4427 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4428 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4429 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4430 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4431 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4432 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4433 4434 # Checks for residue :70. 4435 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74362294539099) 4436 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406797067481, 6) 4437 self.assertAlmostEqual(spin70.phi_ex, 0.312733013751449) 4438 self.assertAlmostEqual(spin70.kex/1000, 4723.09897146338/1000, 6) 4439 self.assertAlmostEqual(spin70.chi2, 363.534044873483) 4440 4441 # Checks for residue :71. 4442 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00776657729728, 5) 4443 self.assertAlmostEqual(spin71.phi_ex, 0.0553787825650613, 5) 4444 self.assertAlmostEqual(spin71.kex/1000, 2781.72292994154/1000, 5) 4445 self.assertAlmostEqual(spin71.chi2, 17.0776399916287, 5)
4446 4447
4449 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4450 4451 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4452 """ 4453 4454 # Base data setup. 4455 self.setup_hansen_cpmg_data(model='LM63 3-site') 4456 4457 # Alias the spins. 4458 spin70 = return_spin(":70") 4459 spin71 = return_spin(":71") 4460 4461 # The R20 keys. 4462 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4463 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4464 4465 ## Set the initial parameter values. 4466 spin70.r2 = {r20_key1: 7.570370921220954, r20_key2: 8.694446951909107} 4467 spin70.phi_ex_B = 0.14872003058250227 4468 spin70.phi_ex_C = 0.1319419923472704 4469 spin70.kB = 4103.672910444741 4470 spin70.kC = 7029.001690726248 4471 spin71.r2 = {r20_key1: 5.1347793381636, r20_key2: 7.156573986051575} 4472 spin71.phi_ex_B = 0.04013553485505605 4473 spin71.phi_ex_C = 0.020050748406928887 4474 spin71.kB = 4045.3007136121364 4475 spin71.kC = 3586.38798270774 4476 4477 #self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 4478 #self.interpreter.minimise.grid_search(lower=None, upper=None, inc=41, constraints=True, verbosity=1) 4479 4480 # Low precision optimisation. 4481 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1) 4482 4483 # Printout. 4484 print("\n\nOptimised parameters:\n") 4485 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4486 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4487 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4488 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin70.phi_ex_B, spin71.phi_ex_B)) 4489 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin70.phi_ex_C, spin71.phi_ex_C)) 4490 print("%-20s %20.15g %20.15g" % ("kB", spin70.kB, spin71.kB)) 4491 print("%-20s %20.15g %20.15g" % ("kC", spin70.kC, spin71.kC)) 4492 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4493 4494 # Checks for residue :70. 4495 self.assertAlmostEqual(spin70.r2[r20_key1], 6.7436230253685, 5) 4496 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406813008828, 6) 4497 self.assertAlmostEqual(spin70.phi_ex_B, 0.206304023079778, 5) 4498 self.assertAlmostEqual(spin70.phi_ex_C, 0.106428983339627, 5) 4499 self.assertAlmostEqual(spin70.kB/1000, 4723.09897652589/1000, 6) 4500 self.assertAlmostEqual(spin70.kC/1000, 4723.09876196409/1000, 6) 4501 self.assertAlmostEqual(spin70.chi2, 363.534044873483, 5) 4502 4503 # Checks for residue :71. 4504 self.assertAlmostEqual(spin71.r2[r20_key1], 4.96612095596752, 5) 4505 self.assertAlmostEqual(spin71.phi_ex_B, 0.00398262266512895, 5) 4506 self.assertAlmostEqual(spin71.phi_ex_C, 0.0555791581291262, 5) 4507 self.assertAlmostEqual(spin71.kB/1000, 1323.33195689832/1000, 5) 4508 self.assertAlmostEqual(spin71.kC/1000, 3149.58971568059/1000, 5) 4509 self.assertAlmostEqual(spin71.chi2, 16.2620934464368)
4510 4511
4513 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D' dispersion model. 4514 4515 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4516 """ 4517 4518 # Base data setup. 4519 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D') 4520 4521 # Alias the spins. 4522 spin70 = return_spin(":70") 4523 spin71 = return_spin(":71") 4524 4525 # The R20 keys. 4526 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4527 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4528 4529 # Set the initial parameter values. 4530 spin70.r2 = {r20_key1: 6.994165925, r20_key2: 9.428129427} 4531 spin70.pA = 0.9897754407 4532 spin70.dw = 5.642418428 4533 spin70.kex = 1743.666375 4534 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4535 spin71.pA = 0.9968032899 4536 spin71.dw = 4.577891393 4537 spin71.kex = 1830.044597 4538 4539 # Low precision optimisation. 4540 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4541 4542 # Printout. 4543 print("\n\nOptimised parameters:\n") 4544 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4545 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4546 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4547 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4548 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4549 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4550 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4551 4552 # Checks for residue :70. 4553 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95797760459016, 4) 4554 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39628959312699, 4) 4555 self.assertAlmostEqual(spin70.pA, 0.989700985380975, 4) 4556 self.assertAlmostEqual(spin70.dw, 5.6733714171086, 4) 4557 self.assertAlmostEqual(spin70.kex/1000, 1713.63101361545/1000, 4) 4558 self.assertAlmostEqual(spin70.chi2, 52.5106928523775, 4) 4559 4560 # Checks for residue :71. 4561 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99893565849977, 4) 4562 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89825625944034, 4) 4563 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 4) 4564 self.assertAlmostEqual(spin71.dw, 2.09292495350993, 4) 4565 self.assertAlmostEqual(spin71.kex/1000, 2438.04423541463/1000, 4) 4566 self.assertAlmostEqual(spin71.chi2, 15.164490242352, 4) 4567 4568 # Test the conversion to k_AB from kex and pA. 4569 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4570 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4571 4572 # Test the conversion to k_BA from kex and pA. 4573 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4574 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4575 4576
4578 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D full' dispersion model. 4579 4580 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4581 """ 4582 4583 # Base data setup. 4584 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D full') 4585 4586 # Alias the spins. 4587 spin70 = return_spin(":70") 4588 spin71 = return_spin(":71") 4589 4590 # The R20 keys. 4591 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4592 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4593 4594 # Set the initial parameter values. 4595 spin70.r2a = {r20_key1: 6.644753428, r20_key2: 7.891776687} 4596 spin70.r2b = {r20_key1: 7.163478485, r20_key2: 138.5170395} 4597 spin70.pA = 0.9884781357 4598 spin70.dw = 5.456507396 4599 spin70.kex = 1906.521189 4600 spin71.r2a = {r20_key1: 4.99893524108981, r20_key2: 100.0} 4601 spin71.r2b = {r20_key1: 8.27456243639973, r20_key2: 100.0} 4602 spin71.pA = 0.986709616684097 4603 spin71.dw = 2.09245158280905 4604 spin71.kex = 2438.2766211401 4605 4606 # Low precision optimisation. 4607 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4608 4609 # Printout. 4610 print("\n\nOptimised parameters:\n") 4611 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4612 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4613 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4614 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4615 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4616 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4617 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4618 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4619 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4620 4621 # Checks for residue :70. 4622 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.61176004043484, 4) 4623 self.assertAlmostEqual(spin70.r2b[r20_key1], 7.4869316381241, 4) 4624 self.assertAlmostEqual(spin70.r2a[r20_key2], 7.78200386067591, 4) 4625 self.assertAlmostEqual(spin70.r2b[r20_key2], 141.703593742468, 4) 4626 self.assertAlmostEqual(spin70.pA, 0.988404987055969, 4) 4627 self.assertAlmostEqual(spin70.dw, 5.4497360203213, 4) 4628 self.assertAlmostEqual(spin70.kex/1000, 1934.09304607082/1000, 4) 4629 self.assertAlmostEqual(spin70.chi2, 44.6793752187925, 4) 4630 4631 # Checks for residue :71. 4632 self.assertAlmostEqual(spin71.r2a[r20_key1], 4.6013095731966, 4) 4633 self.assertAlmostEqual(spin71.r2b[r20_key1], 13.3245678276332, 4) 4634 self.assertAlmostEqual(spin71.r2a[r20_key2], 2.08243621257779, 4) 4635 self.assertAlmostEqual(spin71.r2b[r20_key2], 153.355765094575, 4) 4636 self.assertAlmostEqual(spin71.pA, 0.9665748685124, 4) 4637 self.assertAlmostEqual(spin71.dw, 1.41898001408953, 4) 4638 self.assertAlmostEqual(spin71.kex/1000, 2580.65795560688/1000, 4) 4639 self.assertAlmostEqual(spin71.chi2, 13.4937006732165, 4) 4640 4641 # Test the conversion to k_AB from kex and pA. 4642 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4643 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4644 4645 # Test the conversion to k_BA from kex and pA. 4646 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4647 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4648 4649
4651 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site expanded' dispersion model. 4652 4653 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4654 """ 4655 4656 # Base data setup. 4657 self.setup_hansen_cpmg_data(model='NS CPMG 2-site expanded') 4658 4659 # Alias the spins. 4660 spin70 = return_spin(":70") 4661 spin71 = return_spin(":71") 4662 4663 # The R20 keys. 4664 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4665 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4666 4667 # Set the initial parameter values. 4668 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4669 spin70.pA = 0.9 4670 spin70.dw = 6.0 4671 spin70.kex = 1500.0 4672 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4673 spin71.pA = 0.9 4674 spin71.dw = 4.0 4675 spin71.kex = 1900.0 4676 4677 # Low precision optimisation. 4678 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4679 4680 # Printout. 4681 print("\n\nOptimised parameters:\n") 4682 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4683 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4684 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4685 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4686 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4687 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4688 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4689 4690 # Checks for residue :70. 4691 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95813330991529, 4) 4692 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39663480561524, 4) 4693 self.assertAlmostEqual(spin70.pA, 0.989700843879574, 4) 4694 self.assertAlmostEqual(spin70.dw, 5.67315878825691, 4) 4695 self.assertAlmostEqual(spin70.kex/1000, 1713.56110716632/1000, 4) 4696 self.assertAlmostEqual(spin70.chi2, 52.5106879242812, 4) 4697 4698 # Checks for residue :71. 4699 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99881666793312, 4) 4700 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89817482453042, 4) 4701 self.assertAlmostEqual(spin71.pA, 0.986712911453639, 4) 4702 self.assertAlmostEqual(spin71.dw, 2.09273069372236, 4) 4703 self.assertAlmostEqual(spin71.kex/1000, 2438.20525930405/1000, 4) 4704 self.assertAlmostEqual(spin71.chi2, 15.1644913030633, 4) 4705 4706 # Test the conversion to k_AB from kex and pA. 4707 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4708 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4709 4710 # Test the conversion to k_BA from kex and pA. 4711 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4712 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4713 4714
4716 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star' dispersion model. 4717 4718 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4719 """ 4720 4721 # Base data setup. 4722 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star') 4723 4724 # Alias the spins. 4725 spin70 = return_spin(":70") 4726 spin71 = return_spin(":71") 4727 4728 # The R20 keys. 4729 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4730 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4731 4732 # Set the initial parameter values. 4733 spin70.r2 = {r20_key1: 6.996327746, r20_key2: 9.452051268} 4734 spin70.pA = 0.9897519798 4735 spin70.dw = 5.644862195 4736 spin70.kex = 1723.820567 4737 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4738 spin71.pA = 0.9968032899 4739 spin71.dw = 4.577891393 4740 spin71.kex = 1830.044597 4741 4742 # Low precision optimisation. 4743 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4744 4745 # Printout. 4746 print("\n\nOptimised parameters:\n") 4747 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4748 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4749 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4750 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4751 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4752 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4753 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4754 4755 # Checks for residue :70. 4756 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95543947938561, 1) 4757 self.assertAlmostEqual(spin70.r2[r20_key2], 9.38991914134929, 1) 4758 self.assertAlmostEqual(spin70.pA, 0.989702750971153, 3) 4759 self.assertAlmostEqual(spin70.dw, 5.67527122494516, 1) 4760 self.assertAlmostEqual(spin70.kex/1000, 1715.72032391817/1000, 1) 4761 self.assertAlmostEqual(spin70.chi2, 52.5011991483842, 1) 4762 4763 # Checks for residue :71. 4764 self.assertAlmostEqual(spin71.r2[r20_key1], 4.992594256544, 1) 4765 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 2) 4766 self.assertAlmostEqual(spin71.dw/100, 2.09292495350993/100, 2) 4767 self.assertAlmostEqual(spin71.kex/100000, 2438.04423541463/100000, 2) 4768 self.assertAlmostEqual(spin71.chi2/100, 15.1644902423334/100, 1) 4769 4770 # Test the conversion to k_AB from kex and pA. 4771 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4772 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4773 4774 # Test the conversion to k_BA from kex and pA. 4775 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4776 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4777 4778
4780 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star full' dispersion model. 4781 4782 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4783 """ 4784 4785 # Base data setup. 4786 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star full') 4787 4788 # Alias the spins. 4789 spin70 = return_spin(":70") 4790 spin71 = return_spin(":71") 4791 4792 # The R20 keys. 4793 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4794 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4795 4796 # Set the initial parameter values. 4797 spin70.r2a = {r20_key1: 6.44836878645126, r20_key2: 7.00382877393494} 4798 spin70.r2b = {r20_key1: 12.2083127421994, r20_key2: 199.862962628402} 4799 spin70.pA = 0.987648082613451 4800 spin70.dw = 5.30679853807572 4801 spin70.kex = 2033.25380420666 4802 spin71.r2a = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4803 spin71.r2b = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4804 spin71.pA = 0.992258541625787 4805 spin71.dw = 2.75140650899058 4806 spin71.kex = 2106.60885247431 4807 4808 # Low precision optimisation. 4809 self.interpreter.minimise.calculate() 4810 4811 # Checks for residue :70. 4812 self.assertAlmostEqual(spin70.chi2/10, 45.773987568491123/10, 2) 4813 self.assertAlmostEqual(spin71.chi2/10, 17.329385665659192/10, 2)
4814 4815
4816 - def test_hansen_cpmgfit_input(self):
4817 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CPMGFit. 4818 4819 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4820 """ 4821 4822 # Load the R2eff results file. 4823 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 4824 self.interpreter.results.read(file_name) 4825 self.interpreter.deselect.spin(':4') 4826 4827 # Set up the model. 4828 self.interpreter.relax_disp.select_model('LM63') 4829 4830 # Generate the input files. 4831 self.interpreter.relax_disp.cpmgfit_input(force=True, dir=ds.tmpdir) 4832 4833 # What the files should contain. 4834 batch_file = ['#! /bin/sh\n', '\n', 'cpmgfit -grid -xmgr -f spin_70_N.in | tee spin_70_N.out\n', 'cpmgfit -grid -xmgr -f spin_71_N.in | tee spin_71_N.out\n'] 4835 spin1 = [ 4836 "title :70@N\n", 4837 "fields 2 11.7432964915 18.7892743865\n", 4838 "function CPMG\n", 4839 "R2 1 10 20\n", 4840 "Rex 0 100.0 100\n", 4841 "Tau 0 10.0 100\n", 4842 "xmgr\n", 4843 "@ xaxis label \"1/tcp (1/ms)\"\n", 4844 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 4845 "@ xaxis ticklabel format decimal\n", 4846 "@ yaxis ticklabel format decimal\n", 4847 "@ xaxis ticklabel char size 0.8\n", 4848 "@ yaxis ticklabel char size 0.8\n", 4849 "@ world xmin 0.0\n", 4850 "data\n", 4851 "0.133333 16.045541 0.310925 11.743296 \n", 4852 "0.266667 14.877925 0.303217 11.743296 \n", 4853 "0.400000 14.357820 0.299894 11.743296 \n", 4854 "0.533333 12.664495 0.289532 11.743296 \n", 4855 "0.666667 12.363205 0.287760 11.743296 \n", 4856 "0.800000 11.092532 0.280514 11.743296 \n", 4857 "0.933333 10.566090 0.277619 11.743296 \n", 4858 "1.066667 9.805807 0.273544 11.743296 \n", 4859 "1.200000 9.564301 0.272276 11.743296 \n", 4860 "1.333333 9.015634 0.269442 11.743296 \n", 4861 "1.466667 8.607765 0.267375 11.743296 \n", 4862 "1.600000 8.279997 0.265740 11.743296 \n", 4863 "1.733333 8.474536 0.266708 11.743296 \n", 4864 "1.866667 8.158973 0.265141 11.743296 \n", 4865 "2.000000 7.988631 0.264304 11.743296 \n", 4866 "0.133333 22.224914 0.166231 18.789274 \n", 4867 "0.266667 21.230874 0.162377 18.789274 \n", 4868 "0.400000 20.603704 0.160017 18.789274 \n", 4869 "0.533333 20.327797 0.158996 18.789274 \n", 4870 "0.666667 18.855377 0.153719 18.789274 \n", 4871 "0.800000 18.537531 0.152617 18.789274 \n", 4872 "0.933333 17.508069 0.149138 18.789274 \n", 4873 "1.066667 16.035604 0.144391 18.789274 \n", 4874 "1.200000 15.168192 0.141717 18.789274 \n", 4875 "1.333333 14.431802 0.139516 18.789274 \n", 4876 "1.466667 14.034137 0.138354 18.789274 \n", 4877 "1.600000 12.920148 0.135192 18.789274 \n", 4878 "1.733333 12.653673 0.134456 18.789274 \n", 4879 "1.866667 12.610864 0.134338 18.789274 \n", 4880 "2.000000 11.969303 0.132601 18.789274 \n" 4881 ] 4882 spin2 = [ 4883 "title :71@N\n", 4884 "fields 2 11.7432964915 18.7892743865\n", 4885 "function CPMG\n", 4886 "R2 1 10 20\n", 4887 "Rex 0 100.0 100\n", 4888 "Tau 0 10.0 100\n", 4889 "xmgr\n", 4890 "@ xaxis label \"1/tcp (1/ms)\"\n", 4891 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 4892 "@ xaxis ticklabel format decimal\n", 4893 "@ yaxis ticklabel format decimal\n", 4894 "@ xaxis ticklabel char size 0.8\n", 4895 "@ yaxis ticklabel char size 0.8\n", 4896 "@ world xmin 0.0\n", 4897 "data\n", 4898 "0.133333 7.044342 0.170035 11.743296 \n", 4899 "0.266667 6.781033 0.169228 11.743296 \n", 4900 "0.400000 6.467623 0.168279 11.743296 \n", 4901 "0.533333 6.333340 0.167876 11.743296 \n", 4902 "0.666667 6.323238 0.167846 11.743296 \n", 4903 "0.800000 6.005245 0.166902 11.743296 \n", 4904 "0.933333 5.767052 0.166203 11.743296 \n", 4905 "1.066667 5.476968 0.165361 11.743296 \n", 4906 "1.200000 5.469949 0.165341 11.743296 \n", 4907 "1.333333 5.295113 0.164838 11.743296 \n", 4908 "1.466667 5.435648 0.165242 11.743296 \n", 4909 "1.600000 5.410400 0.165169 11.743296 \n", 4910 "1.733333 5.437554 0.165247 11.743296 \n", 4911 "1.866667 5.176844 0.164501 11.743296 \n", 4912 "2.000000 5.227232 0.164644 11.743296 \n", 4913 "0.133333 11.530903 0.081928 18.789274 \n", 4914 "0.266667 10.983094 0.081041 18.789274 \n", 4915 "0.400000 10.512403 0.080294 18.789274 \n", 4916 "0.533333 9.984805 0.079473 18.789274 \n", 4917 "0.666667 9.573163 0.078845 18.789274 \n", 4918 "0.800000 9.178810 0.078253 18.789274 \n", 4919 "0.933333 8.935719 0.077893 18.789274 \n", 4920 "1.066667 8.610147 0.077416 18.789274 \n", 4921 "1.200000 8.353778 0.077045 18.789274 \n", 4922 "1.333333 8.173729 0.076787 18.789274 \n", 4923 "1.466667 8.091607 0.076670 18.789274 \n", 4924 "1.600000 7.706420 0.076126 18.789274 \n", 4925 "1.733333 7.709125 0.076129 18.789274 \n", 4926 "1.866667 7.610856 0.075992 18.789274 \n", 4927 "2.000000 7.552584 0.075911 18.789274 \n", 4928 ] 4929 4930 # Check the batch file. 4931 print("\nChecking the batch file.") 4932 file = open("%s%sbatch_run.sh" % (ds.tmpdir, sep)) 4933 lines = file.readlines() 4934 file.close() 4935 for i in range(len(lines)): 4936 self.assertEqual(batch_file[i], lines[i]) 4937 4938 # Check spin :70@N. 4939 print("\nChecking the spin :70@N input file.") 4940 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_70_N')) 4941 lines = file.readlines() 4942 file.close() 4943 for i in range(len(spin1)): 4944 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 4945 for i in range(len(lines)): 4946 self.assertEqual(spin1[i], lines[i]) 4947 4948 # Check spin :71@N. 4949 print("\nChecking the spin :71@N input file.") 4950 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_71_N')) 4951 lines = file.readlines() 4952 file.close() 4953 for i in range(len(lines)): 4954 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 4955 for i in range(len(spin2)): 4956 self.assertEqual(spin2[i], lines[i])
4957 4958
4960 """Optimisation of the Korzhnev et al., 2005 15N DQ CPMG data using the 'NS MMQ 2-site' model. 4961 4962 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 4963 4964 Here only the 15N DQ data will be optimised. The values found by cpmg_fit using just this data are: 4965 4966 - r2 = {'500': 9.487269007171426, '600': 11.718267257562591, '800': 13.624551743116887}, 4967 - pA = 0.965402506690231, 4968 - dw = 0.805197170133360, 4969 - dwH = -0.595536627771890, 4970 - kex = 569.003663067619868, 4971 - chi2 = 9.297671357952812. 4972 """ 4973 4974 # Base data setup. 4975 self.setup_korzhnev_2005_data(data_list=['DQ']) 4976 4977 # Alias the spin. 4978 spin = return_spin(":9@N") 4979 4980 # The R20 keys. 4981 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 4982 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 4983 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 4984 4985 # Set the initial parameter values. 4986 spin.r2 = {r20_key1: 9.48527908326952, r20_key2: 11.7135951595536, r20_key3: 13.6153887849344} 4987 spin.pA = 0.965638501551899 4988 spin.dw = 2.8537583461577 4989 spin.dwH = -0.387633062766635 4990 spin.kex = 573.704033851592 4991 4992 # Low precision optimisation. 4993 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 4994 4995 # Monte Carlo simulations. 4996 self.interpreter.monte_carlo.setup(number=2) 4997 self.interpreter.monte_carlo.create_data(method='back_calc') 4998 self.interpreter.monte_carlo.initial_values() 4999 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5000 self.interpreter.monte_carlo.error_analysis() 5001 5002 # Plot the dispersion curves. 5003 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5004 5005 # Save the results. 5006 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5007 5008 # Printout. 5009 print("\n\nOptimised parameters:\n") 5010 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5011 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5012 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5013 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5014 print("%-20s %20.15g" % ("pA", spin.pA)) 5015 print("%-20s %20.15g" % ("dw", spin.dw)) 5016 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5017 print("%-20s %20.15g" % ("kex", spin.kex)) 5018 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5019 5020 # Checks for residue :9. 5021 self.assertAlmostEqual(spin.r2[r20_key1], 9.4870656457415, 2) 5022 self.assertAlmostEqual(spin.r2[r20_key2], 11.7183291788929, 2) 5023 self.assertAlmostEqual(spin.r2[r20_key3], 13.6241729933153, 2) 5024 self.assertAlmostEqual(spin.pA, 0.965405468217295, 4) 5025 self.assertAlmostEqual(spin.dw, 2.76835528427355, 1) 5026 self.assertAlmostEqual(spin.dwH, -0.396489341086363, 2) 5027 self.assertAlmostEqual(spin.kex/1000, 569.06937047601/1000, 3) 5028 self.assertAlmostEqual(spin.chi2, 9.29767487125257, 2)
5029 5030
5032 """Optimisation of the Korzhnev et al., 2005 15N MQ CPMG data using the 'NS MMQ 2-site' model. 5033 5034 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5035 5036 Here only the 15N MQ data will be optimised. The values found by cpmg_fit using just this data are: 5037 5038 - r2 = {'500': 5.993083514798655, '600': 6.622184438384841, '800': 8.640765919352019}, 5039 - pA = 0.930027999814003, 5040 - dw = 4.338620619954370, 5041 - dwH = -0.274250775560818, 5042 - kex = 344.613362916544475, 5043 - chi2 = 10.367733168217050. 5044 """ 5045 5046 # Base data setup. 5047 self.setup_korzhnev_2005_data(data_list=['MQ']) 5048 5049 # Alias the spin. 5050 spin = return_spin(":9@N") 5051 5052 # The R20 keys. 5053 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5054 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5055 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5056 5057 # Set the initial parameter values. 5058 spin.r2 = {r20_key1: 6.02016436619016, r20_key2: 6.65421500772308, r20_key3: 8.6729591487622} 5059 spin.pA = 0.930083249288083 5060 spin.dw = 4.33890689462363 5061 spin.dwH = -0.274316585638047 5062 spin.kex = 344.329651956132 5063 5064 # Low precision optimisation. 5065 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5066 5067 # Monte Carlo simulations. 5068 self.interpreter.monte_carlo.setup(number=2) 5069 self.interpreter.monte_carlo.create_data(method='back_calc') 5070 self.interpreter.monte_carlo.initial_values() 5071 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5072 self.interpreter.monte_carlo.error_analysis() 5073 5074 # Plot the dispersion curves. 5075 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5076 5077 # Save the results. 5078 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5079 5080 # Printout. 5081 print("\n\nOptimised parameters:\n") 5082 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5083 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5084 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5085 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5086 print("%-20s %20.15g" % ("pA", spin.pA)) 5087 print("%-20s %20.15g" % ("dw", spin.dw)) 5088 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5089 print("%-20s %20.15g" % ("kex", spin.kex)) 5090 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5091 5092 # Checks for residue :9. 5093 self.assertAlmostEqual(spin.r2[r20_key1], 5.99503641023038, 1) 5094 self.assertAlmostEqual(spin.r2[r20_key2], 6.62432897608527, 1) 5095 self.assertAlmostEqual(spin.r2[r20_key3], 8.64278915809492, 1) 5096 self.assertAlmostEqual(spin.pA, 0.930036474040713, 3) 5097 self.assertAlmostEqual(spin.dw, 4.33848403058432, 2) 5098 self.assertAlmostEqual(spin.dwH, -0.274246558825267, 3) 5099 self.assertAlmostEqual(spin.kex/1000, 344.626563267384/1000, 3) 5100 self.assertAlmostEqual(spin.chi2, 10.3677362372789, 2)
5101 5102
5104 """Optimisation of the Korzhnev et al., 2005 15N SQ CPMG data using the 'NS MMQ 2-site' model. 5105 5106 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5107 5108 Here only the 15N SQ data will be optimised. The values found by cpmg_fit using just this data are: 5109 5110 - r2 = {'500': 8.335037972570017, '600': 8.761366016417508, '800': 10.225001019091822}, 5111 - pA = 0.950003458294991, 5112 - dw = 4.358402855315123, 5113 - kex = 429.906473361926999, 5114 - chi2 = 17.393331915567252. 5115 """ 5116 5117 # Base data setup. 5118 self.setup_korzhnev_2005_data(data_list=['SQ']) 5119 5120 # Alias the spin. 5121 spin = return_spin(":9@N") 5122 5123 # The R20 keys. 5124 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5125 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5126 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5127 5128 # Set the initial parameter values. 5129 spin.r2 = {r20_key1: 8.334232330326190, r20_key2: 8.756773997879968, r20_key3: 10.219320492033058} 5130 spin.pA = 0.950310172115387 5131 spin.dw = 4.356737157889636 5132 spin.kex = 433.176323890829849 5133 5134 # Low precision optimisation. 5135 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5136 5137 # Monte Carlo simulations. 5138 self.interpreter.monte_carlo.setup(number=2) 5139 self.interpreter.monte_carlo.create_data(method='back_calc') 5140 self.interpreter.monte_carlo.initial_values() 5141 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5142 self.interpreter.monte_carlo.error_analysis() 5143 5144 # Plot the dispersion curves. 5145 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5146 5147 # Save the results. 5148 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5149 5150 # Printout. 5151 print("\n\nOptimised parameters:\n") 5152 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5153 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5154 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5155 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5156 print("%-20s %20.15g" % ("pA", spin.pA)) 5157 print("%-20s %20.15g" % ("dw", spin.dw)) 5158 print("%-20s %20.15g" % ("kex", spin.kex)) 5159 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5160 5161 # Checks for residue :9. 5162 self.assertAlmostEqual(spin.r2[r20_key1], 8.33499994313902, 2) 5163 self.assertAlmostEqual(spin.r2[r20_key2], 8.76118738798082, 2) 5164 self.assertAlmostEqual(spin.r2[r20_key3], 10.2250821829928, 1) 5165 self.assertAlmostEqual(spin.pA, 0.950000281516303, 3) 5166 self.assertAlmostEqual(spin.dw, 4.35845318983581, 2) 5167 self.assertAlmostEqual(spin.kex/1000, 429.874510184149/1000, 2) 5168 self.assertAlmostEqual(spin.chi2, 17.3933357984425, 1)
5169 5170
5172 """Optimisation of the Korzhnev et al., 2005 15N ZQ CPMG data using the 'NS MMQ 2-site' model. 5173 5174 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5175 5176 Here only the 15N ZQ data will be optimised. The values found by cpmg_fit using just this data are: 5177 5178 - r2 = {'500': 5.909812628572937, '600': 6.663690132557320, '800': 6.787171647689906}, 5179 - pA = 0.942452612380140, 5180 - dw = 0.858972784230892, 5181 - dwH = 0.087155962730608, 5182 - kex = 373.219151384798920, 5183 - chi2 = 23.863208106025152. 5184 """ 5185 5186 # Base data setup. 5187 self.setup_korzhnev_2005_data(data_list=['ZQ']) 5188 5189 # Alias the spin. 5190 spin = return_spin(":9@N") 5191 5192 # The R20 keys. 5193 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5194 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5195 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5196 5197 # Set the initial parameter values. 5198 spin.r2 = {r20_key1: 5.91033272691614, r20_key2: 6.66368695342258, r20_key3: 6.78922219135537} 5199 spin.pA = 0.942457332074014 5200 spin.dw = 0.850592422908884 5201 spin.dwH = 0.0881272284455416 5202 spin.kex = 372.745483351305 5203 5204 # Low precision optimisation. 5205 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5206 5207 # Monte Carlo simulations. 5208 self.interpreter.monte_carlo.setup(number=2) 5209 self.interpreter.monte_carlo.create_data(method='back_calc') 5210 self.interpreter.monte_carlo.initial_values() 5211 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5212 self.interpreter.monte_carlo.error_analysis() 5213 5214 # Plot the dispersion curves. 5215 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5216 5217 # Save the results. 5218 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5219 5220 # Printout. 5221 print("\n\nOptimised parameters:\n") 5222 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5223 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5224 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5225 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5226 print("%-20s %20.15g" % ("pA", spin.pA)) 5227 print("%-20s %20.15g" % ("dw", spin.dw)) 5228 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5229 print("%-20s %20.15g" % ("kex", spin.kex)) 5230 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5231 5232 # Checks for residue :9. 5233 self.assertAlmostEqual(spin.r2[r20_key1], 5.9098385837035, 2) 5234 self.assertAlmostEqual(spin.r2[r20_key2], 6.66377885876553, 2) 5235 self.assertAlmostEqual(spin.r2[r20_key3], 6.78717432941353, 2) 5236 self.assertAlmostEqual(spin.pA, 0.942457141344462, 4) 5237 self.assertAlmostEqual(spin.dw, 0.84442055695814, 1) 5238 self.assertAlmostEqual(spin.dwH, 0.0886367674566058, 2) 5239 self.assertAlmostEqual(spin.kex/1000, 373.243053643367/1000, 3) 5240 self.assertAlmostEqual(spin.chi2, 23.863211604121, 1)
5241 5242
5244 """Optimisation of the Korzhnev et al., 2005 1H MQ CPMG data using the 'NS MMQ 2-site' model. 5245 5246 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5247 5248 Here only the 1H MQ data will be optimised. The values found by cpmg_fit using just this data are: 5249 5250 - r2 = {'500': -0.000016676911302, '600': 0.036594127620440, '800': 2.131014839635728}, 5251 - pA = 0.936911090448340, 5252 - dw = 4.325314846914845, 5253 - dwH = -0.213870168665628, 5254 - kex = 487.361914835074117, 5255 - chi2 = 14.870371897291138. 5256 """ 5257 5258 # Base data setup. 5259 self.setup_korzhnev_2005_data(data_list=['1H MQ']) 5260 5261 # Alias the spin. 5262 spin = return_spin(":9@N") 5263 5264 # The R20 keys. 5265 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5266 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5267 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5268 5269 # Set the initial parameter values. 5270 spin.r2 = {r20_key1: 0.000022585022901, r20_key2: 0.039223196112941, r20_key3: 2.136576686700357} 5271 spin.pA = 0.936884348941701 5272 spin.dw = 4.326454531583964 5273 spin.dwH = -0.214026093221782 5274 spin.kex = 487.043592705469223 5275 5276 # Low precision optimisation. 5277 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=100) 5278 5279 # Monte Carlo simulations. 5280 self.interpreter.monte_carlo.setup(number=2) 5281 self.interpreter.monte_carlo.create_data(method='back_calc') 5282 self.interpreter.monte_carlo.initial_values() 5283 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5284 self.interpreter.monte_carlo.error_analysis() 5285 5286 # Plot the dispersion curves. 5287 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5288 5289 # Save the results. 5290 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5291 5292 # Printout. 5293 print("\n\nOptimised parameters:\n") 5294 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5295 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5296 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5297 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5298 print("%-20s %20.15g" % ("pA", spin.pA)) 5299 print("%-20s %20.15g" % ("dw", spin.dw)) 5300 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5301 print("%-20s %20.15g" % ("kex", spin.kex)) 5302 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5303 5304 # Checks for residue :9. 5305 self.assertAlmostEqual(spin.r2[r20_key1], 2.48493199969936e-05, 4) 5306 self.assertAlmostEqual(spin.r2[r20_key2], 0.0382382195911849, 2) 5307 self.assertAlmostEqual(spin.r2[r20_key3], 2.13397221524655, 2) 5308 self.assertAlmostEqual(spin.pA, 0.936879359956996, 4) 5309 self.assertAlmostEqual(spin.dw, 4.32573362253701, 2) 5310 self.assertAlmostEqual(spin.dwH, -0.213951762275293, 2) 5311 self.assertAlmostEqual(spin.kex/1000, 487.021196851596/1000, 4) 5312 self.assertAlmostEqual(spin.chi2, 14.8704048958378, 2)
5313 5314
5316 """Optimisation of the Korzhnev et al., 2005 1H SQ CPMG data using the 'NS MMQ 2-site' model. 5317 5318 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5319 5320 Here only the 1H SQ data will be optimised. The values found by cpmg_fit using just this data are: 5321 5322 - r2 = {'500': 6.691697587650816, '600': 6.998915158708793, '800': 5.519267837559072}, 5323 - pA = 0.946949480545876, 5324 - dwH = -0.265279672133308, 5325 - kex = 406.548178869750700, 5326 - chi2 = 50.400680290545026. 5327 """ 5328 5329 # Base data setup. 5330 self.setup_korzhnev_2005_data(data_list=['1H SQ']) 5331 5332 # Alias the spin. 5333 spin = return_spin(":9@N") 5334 5335 # The R20 keys. 5336 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5337 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5338 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5339 5340 # Set the initial parameter values. 5341 spin.r2 = {r20_key1: 6.69107911078939, r20_key2: 6.99888898689085, r20_key3: 5.52012880268077} 5342 spin.pA = 0.946990967372467 5343 spin.dwH = -0.265308128403529 5344 spin.kex = 406.843250675648 5345 5346 # Low precision optimisation. 5347 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5348 5349 # Monte Carlo simulations. 5350 self.interpreter.monte_carlo.setup(number=2) 5351 self.interpreter.monte_carlo.create_data(method='back_calc') 5352 self.interpreter.monte_carlo.initial_values() 5353 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5354 self.interpreter.monte_carlo.error_analysis() 5355 5356 # Plot the dispersion curves. 5357 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5358 5359 # Save the results. 5360 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5361 5362 # Printout. 5363 print("\n\nOptimised parameters:\n") 5364 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5365 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5366 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5367 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5368 print("%-20s %20.15g" % ("pA", spin.pA)) 5369 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5370 print("%-20s %20.15g" % ("kex", spin.kex)) 5371 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5372 5373 # Checks for residue :9. 5374 self.assertAlmostEqual(spin.r2[r20_key1], 6.69168251154302, 2) 5375 self.assertAlmostEqual(spin.r2[r20_key2], 6.99900388754043, 2) 5376 self.assertAlmostEqual(spin.r2[r20_key3], 5.51921590064843, 2) 5377 self.assertAlmostEqual(spin.pA, 0.946951877648819, 4) 5378 self.assertAlmostEqual(spin.dwH, -0.265280175525516, 3) 5379 self.assertAlmostEqual(spin.kex/1000, 406.566453278183/1000, 2) 5380 self.assertAlmostEqual(spin.chi2, 50.4006836222044, 1)
5381 5382
5384 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5385 5386 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5387 5388 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5389 5390 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5391 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5392 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5393 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5394 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5395 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5396 - pA = 0.943125351763911, 5397 - dw = 4.421827493809807, 5398 - dwH = -0.272637034755752, 5399 - kex = 360.609744568697238, 5400 - chi2 = 162.589570340050813. 5401 """ 5402 5403 # Base data setup. 5404 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5405 5406 # Alias the spin. 5407 spin = return_spin(":9@N") 5408 5409 # The R20 keys. 5410 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5411 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5412 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5413 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5414 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5415 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5416 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5417 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5418 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5419 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5420 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5421 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5422 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5423 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5424 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5425 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5426 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5427 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5428 5429 # Set the initial parameter values. 5430 spin.r2 = { 5431 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5432 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5433 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5434 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5435 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5436 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5437 } 5438 spin.pA = 0.943129019477673 5439 spin.dw = 4.42209952545181 5440 spin.dwH = -0.27258970590969 5441 spin.kex = 360.516132791038 5442 5443 # Low precision optimisation. 5444 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=10) 5445 5446 # Monte Carlo simulations. 5447 self.interpreter.monte_carlo.setup(number=2) 5448 self.interpreter.monte_carlo.create_data(method='back_calc') 5449 self.interpreter.monte_carlo.initial_values() 5450 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5451 self.interpreter.monte_carlo.error_analysis() 5452 5453 # Plot the dispersion curves. 5454 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5455 5456 # Save the results. 5457 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5458 5459 # Printout. 5460 print("\n\nOptimised parameters:\n") 5461 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5462 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5463 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5464 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5465 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5466 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5467 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5468 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5469 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5470 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5471 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5472 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5473 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5474 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5475 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5476 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5477 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5478 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5479 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5480 print("%-20s %20.15g" % ("pA", spin.pA)) 5481 print("%-20s %20.15g" % ("dw", spin.dw)) 5482 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5483 print("%-20s %20.15g" % ("kex", spin.kex)) 5484 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5485 5486 # Checks for residue :9. 5487 self.assertAlmostEqual(spin.r2[r20_key1], 6.67288025927458, 4) 5488 self.assertAlmostEqual(spin.r2[r20_key2], 6.98951408255098, 4) 5489 self.assertAlmostEqual(spin.r2[r20_key3], 5.52959273852704, 4) 5490 self.assertAlmostEqual(spin.r2[r20_key4], 8.39471048876782, 4) 5491 self.assertAlmostEqual(spin.r2[r20_key5], 8.89290699178799, 4) 5492 self.assertAlmostEqual(spin.r2[r20_key6], 10.4077068723693, 4) 5493 self.assertAlmostEqual(spin.r2[r20_key7], 5.93611174376373, 4) 5494 self.assertAlmostEqual(spin.r2[r20_key8], 6.71735669582514, 4) 5495 self.assertAlmostEqual(spin.r2[r20_key9], 6.83835225518265, 4) 5496 self.assertAlmostEqual(spin.r2[r20_key10], 8.59615074668922, 4) 5497 self.assertAlmostEqual(spin.r2[r20_key11], 10.6512137889291, 4) 5498 self.assertAlmostEqual(spin.r2[r20_key12], 12.5710822919109, 4) 5499 self.assertAlmostEqual(spin.r2[r20_key13], 7.85956711501608, 4) 5500 self.assertAlmostEqual(spin.r2[r20_key14], 8.41891642907918, 4) 5501 self.assertAlmostEqual(spin.r2[r20_key15], 11.2362089223038, 4) 5502 self.assertAlmostEqual(spin.r2[r20_key16], 9.1965486378935, 4) 5503 self.assertAlmostEqual(spin.r2[r20_key17], 9.86031627358462, 4) 5504 self.assertAlmostEqual(spin.r2[r20_key18], 11.9752375592575, 4) 5505 self.assertAlmostEqual(spin.pA, 0.943129019477673, 4) 5506 self.assertAlmostEqual(spin.dw, 4.42209952545181, 4) 5507 self.assertAlmostEqual(spin.dwH, -0.27258970590969, 4) 5508 self.assertAlmostEqual(spin.kex/1000, 360.516132791038/1000, 4) 5509 self.assertAlmostEqual(spin.chi2/1000, 162.596331278669/1000, 3)
5510 5511
5513 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5514 5515 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5516 5517 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5518 5519 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5520 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5521 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5522 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5523 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5524 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5525 - pA = 0.943125351763911, 5526 - dw = 4.421827493809807, 5527 - dwH = -0.272637034755752, 5528 - kex = 360.609744568697238, 5529 - chi2 = 162.589570340050813. 5530 """ 5531 5532 # Base data setup. 5533 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5534 5535 # Alias the spin. 5536 spin = return_spin(":9@N") 5537 5538 # The R20 keys. 5539 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5540 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5541 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5542 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5543 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5544 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5545 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5546 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5547 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5548 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5549 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5550 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5551 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5552 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5553 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5554 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5555 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5556 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5557 5558 # Set the initial parameter values. 5559 spin.r2 = { 5560 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5561 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5562 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5563 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5564 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5565 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5566 } 5567 spin.pA = 0.943129019477673 5568 spin.dw = 4.42209952545181 5569 spin.dwH = -0.27258970590969 5570 spin.kex = 360.516132791038 5571 5572 # Calc the chi2 values at these parameters. 5573 self.interpreter.minimise.calculate(verbosity=1) 5574 5575 # Printout. 5576 print("\n\nOptimised parameters:\n") 5577 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5578 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5579 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5580 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5581 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5582 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5583 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5584 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5585 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5586 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5587 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5588 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5589 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5590 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5591 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5592 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5593 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5594 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5595 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5596 print("%-20s %20.15g" % ("pA", spin.pA)) 5597 print("%-20s %20.15g" % ("dw", spin.dw)) 5598 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5599 print("%-20s %20.15g" % ("kex", spin.kex)) 5600 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5601 5602 # Checks for residue :9. 5603 self.assertAlmostEqual(spin.chi2/1000, 162.511988511609/1000, 3)
5604 5605
5607 """Check of all possible dispersion graphs from optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5608 5609 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5610 5611 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5612 5613 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5614 - 0.483 0.89623903 2.4503699912708878 5615 - 0.545 1.1694838 5616 - 0.545 1.1761503 5617 - 0.622 1.294 5618 - 0.669 1.5176493 5619 - 0.722 1.6238791 5620 - 0.813 1.9395758 5621 - 1.011 2.3558415 10.547000429321157 5622 """ 5623 5624 # Base data setup. 5625 model = 'TSMFK01' 5626 expfolder = "acbp_cpmg_disp_048MGuHCl_40C_041223" 5627 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model=model, expfolder=expfolder) 5628 5629 # Alias the spins. 5630 res61L = cdp.mol[0].res[0].spin[0] 5631 5632 # The R20 keys. 5633 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5634 5635 # Set the initial parameter values. 5636 res61L.r2a = {r20_key1: 8.0} 5637 res61L.dw = 6.5 5638 res61L.k_AB = 2.5 5639 5640 # Low precision optimisation. 5641 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5642 5643 # Start testing all possible combinations of graphs. 5644 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 5645 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 5646 interpolate_types = [INTERPOLATE_DISP] 5647 5648 # Write to temp folder. 5649 result_dir_name = ds.tmpdir 5650 result_folders = [model] 5651 spin_id = ":61@N" 5652 5653 # Loop through all possible combinations of y_axis, x_axis and interpolation. 5654 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder+sep+'check_graphs' 5655 5656 for result_folder in result_folders: 5657 for y_axis in y_axis_types: 5658 for x_axis in x_axis_types: 5659 for interpolate in interpolate_types: 5660 # Determine file name: 5661 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 5662 5663 # Make the file name. 5664 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 5665 5666 # Write the curves. 5667 dir = result_dir_name+sep+result_folder 5668 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 5669 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 5670 5671 # Get the file path. 5672 file_path = get_file_path(file_name, dir) 5673 5674 # Test the plot file exists. 5675 print("Testing file access to graph: %s"%file_path) 5676 self.assert_(access(file_path, F_OK)) 5677 5678 # Now open, and compare content, line by line. 5679 file_prod = open(file_path) 5680 lines_prod = file_prod.readlines() 5681 file_prod.close() 5682 5683 # Define file to compare against. 5684 dir_comp = data_path+sep+result_folder 5685 file_path_comp = get_file_path(file_name, dir_comp) 5686 file_comp = open(file_path_comp) 5687 lines_comp = file_comp.readlines() 5688 file_comp.close() 5689 5690 ## Assert number of lines is equal. 5691 self.assertEqual(len(lines_prod), len(lines_comp)) 5692 for j in range(len(lines_prod)): 5693 # Make the string test 5694 first_char = lines_prod[j][0] 5695 if first_char in ["@", "&"]: 5696 self.assertEqual(lines_prod[j], lines_comp[j]) 5697 else: 5698 # Split string in x, y, error. 5699 # The error would change per run. 5700 x_prod, y_prod, y_prod_err = lines_prod[j].split() 5701 x_comp, y_comp, y_comp_err = lines_comp[j].split() 5702 self.assertAlmostEqual(float(x_prod), float(x_comp)) 5703 self.assertAlmostEqual(float(y_prod), float(y_comp)) 5704 self.assertAlmostEqual(float(y_prod_err), float(y_comp_err))
5705 5706
5708 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5709 5710 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5711 """ 5712 5713 # Base data setup. 5714 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5715 5716 # Alias the spins. 5717 res61L = cdp.mol[0].res[0].spin[0] 5718 5719 # The R20 keys. 5720 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5721 5722 # Set the initial parameter values. 5723 res61L.r2 = {r20_key1: 8.0} 5724 res61L.pA = 0.9 5725 res61L.dw = 6.0 5726 res61L.kex = 600.0 5727 5728 # Low precision optimisation. 5729 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5730 5731 # Printout. 5732 print("\n\nOptimised parameters:\n") 5733 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5734 print("%-20s %20.15g" % ("R2 (600 MHz)", res61L.r2[r20_key1])) 5735 print("%-20s %20.15g" % ("pA", res61L.pA)) 5736 print("%-20s %20.15g" % ("dw", res61L.dw)) 5737 print("%-20s %20.15g" % ("kex", res61L.kex)) 5738 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5739 5740 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5741 self.assertAlmostEqual(res61L.r2[r20_key1], 8.69277980194016, 4) 5742 self.assertAlmostEqual(res61L.pA, 0.9943781590842946, 5) 5743 self.assertAlmostEqual(res61L.dw, 6.389453131263374, 3) 5744 self.assertAlmostEqual(res61L.kex, 609.262167216419, 0) 5745 self.assertAlmostEqual(res61L.chi2, 65.99987828889657, 5) 5746 5747 # Test the conversion to k_AB from kex and pA. 5748 self.assertEqual(res61L.k_AB, res61L.kex * (1.0 - res61L.pA)) 5749 5750 # Test the conversion to k_BA from kex and pA. 5751 self.assertEqual(res61L.k_BA, res61L.kex * res61L.pA)
5752 5753
5755 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5756 5757 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5758 """ 5759 5760 # Base data setup. 5761 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72 full', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5762 5763 # Alias the spins. 5764 res61L = cdp.mol[0].res[0].spin[0] 5765 5766 # The R20 keys. 5767 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5768 5769 # Set the initial parameter values. 5770 res61L.r2a = {r20_key1: 8.0} 5771 res61L.r2b = {r20_key1: 105.0} 5772 res61L.pA = 0.9 5773 res61L.dw = 6.0 5774 res61L.kex = 500.0 5775 5776 # Low precision optimisation. 5777 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5778 5779 # Printout. 5780 print("\n\nOptimised parameters:\n") 5781 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5782 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5783 print("%-20s %20.15g" % ("R2B (600 MHz)", res61L.r2b[r20_key1])) 5784 print("%-20s %20.15g" % ("pA", res61L.pA)) 5785 print("%-20s %20.15g" % ("dw", res61L.dw)) 5786 print("%-20s %20.15g" % ("kex", res61L.kex)) 5787 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5788 5789 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5790 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.044428899438309, 0) 5791 self.assertAlmostEqual(res61L.r2b[r20_key1], 105.11894506392449, -2) 5792 self.assertAlmostEqual(res61L.pA, 0.992066883657578, 2) 5793 self.assertAlmostEqual(res61L.dw, 6.389453586338883, 3) 5794 self.assertAlmostEqual(res61L.kex, 513.483608742063, -2) 5795 self.assertAlmostEqual(res61L.chi2, 65.99987828890289, 5)
5796 5797
5799 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5800 5801 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5802 5803 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5804 5805 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5806 - 0.483 0.89623903 2.4503699912708878 5807 - 0.545 1.1694838 5808 - 0.545 1.1761503 5809 - 0.622 1.294 5810 - 0.669 1.5176493 5811 - 0.722 1.6238791 5812 - 0.813 1.9395758 5813 - 1.011 2.3558415 10.547000429321157 5814 """ 5815 5816 # Base data setup. 5817 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5818 5819 # Alias the spins. 5820 res61L = cdp.mol[0].res[0].spin[0] 5821 5822 # The R20 keys. 5823 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5824 5825 # Set the initial parameter values. 5826 res61L.r2a = {r20_key1: 8.0} 5827 res61L.dw = 6.5 5828 res61L.k_AB = 2.5 5829 5830 # Low precision optimisation. 5831 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5832 5833 # Printout. 5834 print("\n\nOptimised parameters:\n") 5835 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5836 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5837 print("%-20s %20.15g" % ("dw", res61L.dw)) 5838 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 5839 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5840 5841 # Checks for residue :61. Reference values from paper 5842 5843 self.assertAlmostEqual(res61L.k_AB, 2.45, 1)
5844 5845
5847 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5848 5849 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 1.01 M GuHCl (guanidine hydrochloride). 5850 5851 The comparison is to Figure 2, which is for dataset with 1 M GuHCl. The reported results are expected to be in rad.s^-1. Conversion into relax stored values is preferably. 5852 5853 Representative 15N CPMG relaxation dispersion curve measured on the cross peaks from residue L61 in folded ACBP at pH 5.3, 1 M GuHCl, and 40C: 5854 5855 1. The dotted line represents a residue-specific fit of all parameters in Eq. 1: 5856 - k_AB = 11.3 +/- 0.7 s^-1, 5857 - dw = (2.45 +/- 0.09) * 10^3 s^-1, 5858 - R2 = 8.0 +/- 0.5 s^-1. 5859 5860 2. The solid line represents a global fit of k_AB to all protein residues and a residue-specific fit of dw and R2.: 5861 - k_AB = 10.55 +/- 0.08 s^-1, 5862 - dw = (2.44 +/- 0.08) * 10^3 s^-1, 5863 - R2 = 8.4 +/- 0.3 s^-1. 5864 5865 Conversion of paper results to relax results is performed by: 5866 5867 - dw(ppm) = dw(rad.s^-1) * 10^6 * 1/(2*pi) * (gyro1H/(gyro15N*spectrometer_freq)) = 2.45E3 * 1E6 / (2 * math.pi) * (26.7522212E7/(-2.7126E7 * 599.8908622E6)) = -6.41 ppm. 5868 5869 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5870 5871 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5872 - 0.483 0.89623903 2.4503699912708878 5873 - 0.545 1.1694838 5874 - 0.545 1.1761503 5875 - 0.622 1.294 5876 - 0.669 1.5176493 5877 - 0.722 1.6238791 5878 - 0.813 1.9395758 5879 - 1.011 2.3558415 10.547000429321157 5880 """ 5881 5882 # Base data setup. 5883 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_101MGuHCl_40C_041223") 5884 5885 # Alias the spins. 5886 res61L = cdp.mol[0].res[0].spin[0] 5887 5888 # The R20 keys. 5889 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086270e6) 5890 5891 # Set the initial parameter values. 5892 res61L.r2a = {r20_key1: 8.0} 5893 res61L.dw = 6.5 5894 res61L.k_AB = 11.0 5895 5896 # Low precision optimisation. 5897 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5898 5899 # Printout. 5900 print("\n\nOptimised parameters:\n") 5901 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5902 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5903 print("%-20s %20.15g" % ("dw", res61L.dw)) 5904 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 5905 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5906 5907 # Checks for residue :61. Reference values from paper 5908 5909 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.4, 0) 5910 self.assertAlmostEqual(res61L.dw, 6.41, 0) 5911 self.assertAlmostEqual(res61L.k_AB, 10.55, 0)
5912 5913
5914 - def test_lm63_3site_synthetic(self):
5915 """Test the 'LM63 3-site' dispersion model using the pure noise-free synthetic data.""" 5916 5917 # The path to the data files. 5918 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'lm63_3site' 5919 5920 # Load the state file. 5921 self.interpreter.reset() 5922 self.interpreter.state.load(data_path+sep+'r2eff_values') 5923 5924 # A new data pipe. 5925 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to='LM63 3-site', bundle_to='relax_disp') 5926 self.interpreter.pipe.switch(pipe_name='LM63 3-site') 5927 5928 # Set up the model data. 5929 self.interpreter.relax_disp.select_model(model='LM63 3-site') 5930 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to='LM63 3-site', param='r2eff') 5931 self.interpreter.spin.isotope('15N') 5932 5933 # Alias the spins. 5934 spin1 = return_spin(":1") 5935 spin2 = return_spin(":2") 5936 5937 # The R20 keys. 5938 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5939 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5940 5941 # Manually set the parameter values. 5942 spin1.r2 = {r20_key1: 12.0, r20_key2: 12.0} 5943 spin1.phi_ex_B = 0.1 5944 spin1.phi_ex_C = 0.5 5945 spin1.kB = 1500.0 5946 spin1.kC = 2500.0 5947 spin2.r2 = {r20_key1: 15.0, r20_key2: 15.0} 5948 spin2.phi_ex_B = 0.1 5949 spin2.phi_ex_C = 0.5 5950 spin2.kB = 1500.0 5951 spin2.kC = 2500.0 5952 5953 # Low precision optimisation. 5954 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5955 5956 # Monte Carlo simulations. 5957 self.interpreter.monte_carlo.setup(number=3) 5958 self.interpreter.monte_carlo.create_data(method='back_calc') 5959 self.interpreter.monte_carlo.initial_values() 5960 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-2, grad_tol=None, max_iter=10, constraints=True, scaling=True, verbosity=1) 5961 self.interpreter.monte_carlo.error_analysis() 5962 5963 # Save the results. 5964 self.interpreter.results.write(file='devnull', compress_type=1, force=True) 5965 5966 # The model checks. 5967 print("\n\nOptimised parameters:\n") 5968 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 5969 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 5970 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 5971 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin1.phi_ex_B, spin2.phi_ex_B)) 5972 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin1.phi_ex_C, spin2.phi_ex_C)) 5973 print("%-20s %20.15g %20.15g" % ("kB", spin1.kB, spin2.kB)) 5974 print("%-20s %20.15g %20.15g" % ("kC", spin1.kC, spin2.kC)) 5975 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 5976 self.assertAlmostEqual(spin1.r2[r20_key1], 12.0, 2) 5977 self.assertAlmostEqual(spin1.r2[r20_key2], 12.0, 2) 5978 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 5979 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 5980 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 5981 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 5982 self.assertAlmostEqual(spin1.chi2, 0.0, 3) 5983 self.assertAlmostEqual(spin2.r2[r20_key1], 15.0, 3) 5984 self.assertAlmostEqual(spin2.r2[r20_key2], 15.0, 3) 5985 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 5986 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 5987 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 5988 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 5989 self.assertAlmostEqual(spin2.chi2, 0.0, 3)
5990 5991
5992 - def test_m61_data_to_m61(self):
5993 """Test the relaxation dispersion 'M61' model curve fitting to fixed time synthetic data.""" 5994 5995 # Fixed time variable. 5996 ds.fixed = True 5997 5998 # Execute the script. 5999 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py') 6000 6001 # The original parameters. 6002 i0 = [100000.0, 20000.0] 6003 r1rho_prime = [2.25, 24.0] 6004 pA = 0.7 6005 kex = 1000.0 6006 delta_omega = [1.0, 2.0] 6007 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000'] 6008 phi_ex = [] 6009 for i in range(2): 6010 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 6011 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]] 6012 6013 # Switch to the 'R2eff' model data pipe, then check for each spin. 6014 self.interpreter.pipe.switch('R2eff - relax_disp') 6015 spin_index = 0 6016 for spin, spin_id in spin_loop(return_id=True): 6017 # Printout. 6018 print("\nSpin %s." % spin_id) 6019 6020 # Check the fitted parameters. 6021 for i in range(len(keys)): 6022 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 6023 6024 # Increment the spin index. 6025 spin_index += 1 6026 6027 # The R20 keys. 6028 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6029 6030 # Switch to the 'M61' model data pipe, then check for each spin. 6031 self.interpreter.pipe.switch('M61 - relax_disp') 6032 spin_index = 0 6033 for spin, spin_id in spin_loop(return_id=True): 6034 # Printout. 6035 print("\nSpin %s." % spin_id) 6036 6037 # Check the fitted parameters. 6038 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6039 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 6040 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6041 6042 # Increment the spin index. 6043 spin_index += 1
6044 6045
6046 - def test_m61_exp_data_to_m61(self):
6047 """Test the relaxation dispersion 'M61' model curve fitting to the full exponential synthetic data.""" 6048 6049 # Fixed time variable. 6050 ds.fixed = False 6051 6052 # Single spin optimisation. 6053 ds.single = True 6054 6055 # Execute the script. 6056 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py') 6057 6058 # The original parameters. 6059 i0 = [100000.0, 20000.0] 6060 r1rho_prime = [2.25, 24.0] 6061 pA = 0.7 6062 kex = 1000.0 6063 delta_omega = [1.0, 2.0] 6064 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000'] 6065 phi_ex = [] 6066 for i in range(2): 6067 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 6068 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]] 6069 6070 # Switch to the 'R2eff' model data pipe, then check for each spin. 6071 self.interpreter.pipe.switch('R2eff - relax_disp') 6072 spin_index = 0 6073 for spin, spin_id in spin_loop(return_id=True): 6074 # Printout. 6075 print("\nSpin %s." % spin_id) 6076 6077 # Check the fitted parameters. 6078 for i in range(len(keys)): 6079 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 6080 6081 # Increment the spin index. 6082 spin_index += 1 6083 6084 # The R20 keys. 6085 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6086 6087 # Switch to the 'M61' model data pipe, then check for each spin. 6088 self.interpreter.pipe.switch('M61 - relax_disp') 6089 spin_index = 0 6090 for spin, spin_id in spin_loop(return_id=True): 6091 # Printout. 6092 print("\nSpin %s." % spin_id) 6093 6094 # Check the fitted parameters. 6095 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6096 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 6097 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6098 6099 # Increment the spin index. 6100 spin_index += 1
6101 6102
6103 - def test_m61b_data_to_m61b(self):
6104 """Test the relaxation dispersion 'M61 skew' model curve fitting to fixed time synthetic data.""" 6105 6106 # Execute the script. 6107 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61b.py') 6108 6109 # The original parameters. 6110 i0 = [100000.0, 20000.0] 6111 r1rho_prime = [10.0, 24.0] 6112 pA = 0.95 6113 kex = 2000.0 6114 delta_omega = [1.0, 2.0] 6115 6116 # The R20 keys. 6117 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6118 6119 # Switch to the 'M61 skew' model data pipe, then check for each spin. 6120 self.interpreter.pipe.switch("%s - relax_disp" % MODEL_M61B) 6121 spin_index = 0 6122 for spin, spin_id in spin_loop(return_id=True): 6123 # Printout. 6124 print("\nSpin %s." % spin_id) 6125 6126 # Check the fitted parameters. 6127 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6128 self.assertAlmostEqual(spin.pA, pA, 2) 6129 self.assertAlmostEqual(spin.dw, dw[spin_index], 2) 6130 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6131 6132 # Increment the spin index. 6133 spin_index += 1
6134 6135
6137 """Test that all models which can nest, have all their parameters converted.""" 6138 6139 # Set the experiment type. 6140 cdp.exp_type_list = EXP_TYPE_LIST 6141 6142 # Get info for all models. 6143 all_models_info = models_info(models=MODEL_LIST_FULL) 6144 6145 # Loop over all models. 6146 print("Printing the listed of nested models for each model.") 6147 print("#########################################") 6148 for model_info in all_models_info: 6149 print("%s"%model_info.model), 6150 print("<-"), 6151 nest_list = model_info.nest_list 6152 if nest_list == None: 6153 nest_list = ["None"] 6154 print(', '.join(map(str, nest_list))) 6155 6156 # Skip if there is no model to nest from. 6157 if nest_list == ["None"]: 6158 continue 6159 6160 # Assign params to variable. 6161 model_params = model_info.params 6162 6163 # Now loop over the nested models. 6164 for nested_model in nest_list: 6165 # Get the params for the nested model. 6166 nested_model_params = MODEL_PARAMS[nested_model] 6167 6168 # Get the dictionary of parameter conversion. 6169 par_dic = nesting_param(model_params=model_params, nested_model_params=nested_model_params) 6170 6171 # Test the number of elements in the dictionary. 6172 self.assertEqual(len(par_dic), len(model_params)) 6173 6174 # Loop over dictionary. 6175 for param in par_dic: 6176 if param != par_dic[param]: 6177 print("Model:'%s', Nested model:'%s', Copying '%s' to '%s'." % (model_info.model, nested_model, par_dic[param], param)) 6178 self.assertNotEqual(par_dic[param], None)
6179 6180
6181 - def test_ns_mmq_3site(self):
6182 """Compare the 'NS MMQ 3-site' dispersion model to synthetic data from cpmg_fit.""" 6183 6184 # Execute the script. 6185 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site.py') 6186 6187 # Check the chi-squared value. 6188 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6189 6190
6191 - def test_ns_mmq_3site_linear(self):
6192 """Compare the 'NS MMQ 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 6193 6194 # Execute the script. 6195 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site_linear.py') 6196 6197 # Check the chi-squared value. 6198 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6199 6200
6201 - def test_ns_r1rho_3site(self):
6202 """Compare the 'NS R1rho 3-site' dispersion model to synthetic data from cpmg_fit.""" 6203 6204 # Execute the script. 6205 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site.py') 6206 6207 # Check the chi-squared value. 6208 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 136.13141468674999, 3)
6209 6210
6211 - def test_ns_r1rho_3site_linear(self):
6212 """Compare the 'NS R1rho 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 6213 6214 # Execute the script. 6215 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site_linear.py') 6216 6217 # Check the chi-squared value. 6218 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 0.030959849811015544, 3)
6219 6220
6221 - def test_repeat_cpmg(self):
6222 """Test the protocol for repeated dispersion analysis. The class: relax_disp_repeat_cpmg. 6223 6224 U{task #7826<https://gna.org/task/index.php?7826>}. Write an python class for the repeated analysis of dispersion data. 6225 """ 6226 6227 # Reset. 6228 self.interpreter.reset() 6229 6230 # Define base path to files. 6231 base_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1' 6232 6233 # Setup dictionary with settings. 6234 sdic = {} 6235 6236 # Spectrometer frqs in list. 6237 sfrq_1 = 499.86214 6238 sfrq_2 = 599.8908587 6239 sfrqs = [sfrq_1, sfrq_2] 6240 6241 # Store in dictionary. 6242 sdic['sfrqs'] = sfrqs 6243 6244 # Store unit for frq. 6245 sdic['sfrq_unit'] = 'MHz' 6246 6247 # Store exp_type 6248 sdic['exp_type'] = 'SQ CPMG' 6249 6250 # Store spin isotope 6251 sdic['isotope'] = '15N' 6252 6253 # How intensity was measured. 6254 sdic['int_method'] = 'height' 6255 6256 # Define the time for result directory. 6257 sdic['time'] = '2014_09' 6258 6259 # Initialize frq dics. 6260 for frq in sfrqs: 6261 key = DIC_KEY_FORMAT % (frq) 6262 sdic[key] = {} 6263 6264 # Set keys. 6265 e_1 = DIC_KEY_FORMAT % (sfrq_1) 6266 e_2 = DIC_KEY_FORMAT % (sfrq_2) 6267 6268 # Store time T2. 6269 sdic[e_1]['time_T2'] = 0.04 6270 sdic[e_2]['time_T2'] = 0.06 6271 6272 # Set ncyc. 6273 ncyc_1 = array([20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0]) 6274 ncyc_2 = array([28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 52, 18, 40, 6, 12, 0, 24, 14, 22]) 6275 6276 # Calculate the cpmg_frq and store. 6277 sdic[e_1]['cpmg_frqs'] = ncyc_1 / sdic[e_1]['time_T2'] 6278 sdic[e_2]['cpmg_frqs'] = ncyc_2 / sdic[e_2]['time_T2'] 6279 6280 # Define peak lists. 6281 peaks_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files' 6282 peaks_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files' 6283 sdic[e_1]['peaks_folder'] = peaks_folder_1 6284 sdic[e_2]['peaks_folder'] = peaks_folder_2 6285 6286 # Define folder to all rmsd files. 6287 rmsd_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'ft2_data' 6288 rmsd_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'ft2_data' 6289 sdic[e_1]['rmsd_folder'] = rmsd_folder_1 6290 sdic[e_2]['rmsd_folder'] = rmsd_folder_2 6291 6292 # Define temporary folder. 6293 sdic['results_dir'] = self.tmpdir 6294 6295 # Setup class with data. 6296 RDR = Relax_disp_rep(sdic) 6297 6298 # Setup base information. 6299 RDR.set_base_cpmg(method='FT', glob_ini=128) 6300 6301 methods = ['FT', 'MDD'] 6302 #methods = ['FT'] 6303 6304 # Set the intensity. 6305 #RDR.set_int(methods=methods, list_glob_ini=[128, 126], set_rmsd=False, set_rep=True) 6306 #RDR.set_int(methods=methods, list_glob_ini=[128, 126], set_rmsd=True, set_rep=False) 6307 6308 # Try plot some intensity correlations. 6309 if True: 6310 selection = None 6311 6312 # Now make a spin selection. 6313 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128, 126], selection=selection) 6314 6315 # For mdd 6316 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection) 6317 6318 # Plot correlation of intensity 6319 fig1 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 128]] 6320 fig2 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 126]] 6321 corr_data = [fig1, fig2] 6322 6323 write_stats = True 6324 RDR.plot_int_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6325 6326 # Open stat file. 6327 if write_stats: 6328 for i, corr_data_i in enumerate(corr_data): 6329 data, methods, glob_inis = corr_data[i] 6330 data_x, data_y = data 6331 method_x, method_y = methods 6332 glob_ini_x, glob_ini_y = glob_inis 6333 x = data_x[str(glob_ini_x)]['peak_intensity_arr'] 6334 np = len(x) 6335 6336 file_name_ini = 'int_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np) 6337 6338 if selection == None: 6339 file_name = file_name_ini + '_all.txt' 6340 else: 6341 file_name = file_name_ini + '_sel.txt' 6342 path = RDR.results_dir 6343 data = extract_data(file=file_name, dir=path) 6344 6345 # Loop over the lines. 6346 for i, data_i in enumerate(data): 6347 print(i, data_i) 6348 6349 6350 # Try plot some intensity statistics. 6351 if True: 6352 # Collect r2eff values. 6353 selections = [None, ':2,3'] 6354 for selection in selections: 6355 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128], selection=selection) 6356 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection) 6357 6358 # Get R2eff stats. 6359 int_stat_dic = RDR.get_int_stat_dic(list_int_dics=[int_ft_sel, int_mdd_sel], list_glob_ini=[128, 126]) 6360 6361 ## Plot R2eff stats 6362 write_stats = True 6363 RDR.plot_int_stat(int_stat_dic=int_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126], show=False, write_stats=write_stats) 6364 6365 # Open stat file. 6366 if write_stats: 6367 if selection == None: 6368 file_name = 'int_stat_all.txt' 6369 else: 6370 file_name = 'int_stat_sel.txt' 6371 path = RDR.results_dir 6372 data = extract_data(file=file_name, dir=path) 6373 6374 # Loop over the lines. 6375 for i, data_i in enumerate(data): 6376 print(i, data_i) 6377 6378 6379 # Try write some R2eff correlations. 6380 if True: 6381 selection = None 6382 # Collect r2eff values. 6383 r2eff_ft_all = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection) 6384 6385 # For all spins, mdd 6386 r2eff_mdd_all = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection) 6387 6388 # Plot correlation of intensity 6389 fig1 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 128]] 6390 fig2 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 126]] 6391 corr_data = [fig1, fig2] 6392 6393 write_stats = True 6394 RDR.plot_r2eff_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6395 6396 # Open stat file. 6397 if write_stats: 6398 for i, corr_data_i in enumerate(corr_data): 6399 data, methods, glob_inis = corr_data[i] 6400 data_x, data_y = data 6401 method_x, method_y = methods 6402 glob_ini_x, glob_ini_y = glob_inis 6403 x = data_x[str(glob_ini_x)]['r2eff_arr'] 6404 np = len(x) 6405 6406 file_name_ini = 'r2eff_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np) 6407 6408 if selection == None: 6409 file_name = file_name_ini + '_all.txt' 6410 else: 6411 file_name = file_name_ini + '_sel.txt' 6412 path = RDR.results_dir 6413 data = extract_data(file=file_name, dir=path) 6414 6415 # Loop over the lines. 6416 for i, data_i in enumerate(data): 6417 print(i, data_i) 6418 6419 6420 # Try plot some R2eff statistics. 6421 if True: 6422 # Collect r2eff values. 6423 selections = [None, ':2,3'] 6424 for selection in selections: 6425 r2eff_ft_sel = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection) 6426 r2eff_mdd_sel = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection) 6427 6428 # Get R2eff stats. 6429 r2eff_stat_dic = RDR.get_r2eff_stat_dic(list_r2eff_dics=[r2eff_ft_sel, r2eff_mdd_sel], list_glob_ini=[128, 126]) 6430 6431 ## Plot R2eff stats 6432 write_stats = True 6433 RDR.plot_r2eff_stat(r2eff_stat_dic=r2eff_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6434 6435 # Open stat file. 6436 if write_stats: 6437 if selection == None: 6438 file_name = 'r2eff_stat_all.txt' 6439 else: 6440 file_name = 'r2eff_stat_sel.txt' 6441 path = RDR.results_dir 6442 data = extract_data(file=file_name, dir=path) 6443 6444 # Loop over the lines. 6445 for i, data_i in enumerate(data): 6446 print(i, data_i) 6447 6448 6449 # Do minimisation individual. 6450 if True: 6451 methods = ['FT', 'MDD'] 6452 # Now calculate R2eff. 6453 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126]) 6454 6455 min_methods = [['FT'], ['MDD']] 6456 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]] 6457 6458 #min_methods = [['FT']] 6459 #min_list_glob_ini = [[128]] 6460 #selection = ':2,3' 6461 selection = None 6462 6463 for i, methods in enumerate(min_methods): 6464 list_glob_ini = min_list_glob_ini[i] 6465 6466 if True: 6467 # First get data. 6468 if True: 6469 # First load all data. 6470 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini) 6471 6472 # Then set R20 6473 if True: 6474 # Set R20 from min R2eff in preparation for Grid search. 6475 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, model_from=MODEL_R2EFF, analysis='grid_setup_ind', analysis_from='int', list_glob_ini=list_glob_ini, force=True) 6476 6477 # Check and print parameters. 6478 if True: 6479 # Print for pipe name 6480 method = methods[0] 6481 glob_ini = list_glob_ini[0] 6482 6483 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup_ind', glob_ini=glob_ini) 6484 RDR.spin_display_params(pipe_name=test_pipe_name) 6485 6486 # Then Grid search. 6487 if True: 6488 # Do Grid search. 6489 RDR.minimise_grid_search(inc=4, verbosity=1, methods=methods, model=MODEL_CR72, analysis='grid_setup_ind', list_glob_ini=list_glob_ini, force=True) 6490 6491 # Then Minimise. 6492 if True: 6493 # Minimise 6494 RDR.opt_max_iterations = int(1e2) 6495 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min_ind', analysis_from='grid_setup_ind', list_glob_ini=list_glob_ini, force=True) 6496 6497 #print asd 6498 6499 # Plot statistics. 6500 # Try plot some minimisation correlations. 6501 if True: 6502 selections = [None, ':2,3'] 6503 for selection in selections: 6504 # Collect param values. 6505 analysis = 'min_ind' 6506 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6507 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6508 6509 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]] 6510 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]] 6511 corr_data = [fig1, fig2] 6512 6513 write_stats = True 6514 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6515 6516 # Open stat file. 6517 if write_stats: 6518 for i, corr_data_i in enumerate(corr_data): 6519 data, methods, glob_inis = corr_data[i] 6520 data_x, data_y = data 6521 method_x, method_y = methods 6522 glob_ini_x, glob_ini_y = glob_inis 6523 6524 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y) 6525 6526 if selection == None: 6527 file_name = file_name_ini + '_all.txt' 6528 else: 6529 file_name = file_name_ini + '_sel.txt' 6530 path = RDR.results_dir 6531 data = extract_data(file=file_name, dir=path) 6532 6533 # Loop over the lines. 6534 for i, data_i in enumerate(data): 6535 print(i, data_i) 6536 6537 # Try plot some minimisation statistics. 6538 if True: 6539 # Collect param values. 6540 #selections = [None, ':2,3'] 6541 selections = [None, ':2,3'] 6542 for selection in selections: 6543 analysis = 'min_ind' 6544 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6545 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6546 6547 # Get param stats. 6548 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126]) 6549 6550 ## Plot R2eff stats 6551 write_stats = True 6552 RDR.plot_min_stat(min_stat_dic=min_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6553 6554 # Open stat file. 6555 if write_stats: 6556 if selection == None: 6557 file_name = '%s_stat_all.txt' % (analysis) 6558 else: 6559 file_name = '%s_stat_sel.txt' % (analysis) 6560 path = RDR.results_dir 6561 data = extract_data(file=file_name, dir=path) 6562 6563 # Loop over the lines. 6564 for i, data_i in enumerate(data): 6565 print(i, data_i) 6566 6567 6568 # Do minimisation clustered. 6569 if True: 6570 methods = ['FT', 'MDD'] 6571 # Now calculate R2eff. 6572 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126]) 6573 6574 min_methods = [['FT'], ['MDD']] 6575 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]] 6576 6577 #min_methods = [['FT']] 6578 #min_list_glob_ini = [[128]] 6579 selection = ':2,3' 6580 6581 for i, methods in enumerate(min_methods): 6582 list_glob_ini = min_list_glob_ini[i] 6583 6584 if True: 6585 # First get data. 6586 if True: 6587 # First load all data. 6588 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini) 6589 6590 # Then select spins. 6591 if True: 6592 # Deselect all spins. 6593 RDR.deselect_all(methods=methods, model='setup', model_from=MODEL_R2EFF, analysis='grid_setup', analysis_from='int', list_glob_ini=list_glob_ini, force=True) 6594 6595 RDR.select_spin(spin_id=selection, methods=methods, model='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6596 6597 # Then preset values. 6598 if True: 6599 # Set k_AB for Grid search. 6600 RDR.value_set(methods=methods, val=1000., param='kex', model=MODEL_CR72, model_from='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6601 RDR.value_set(methods=methods, val=0.95, param='pA', model=MODEL_CR72, model_from='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6602 6603 # Then set R20 6604 if True: 6605 # Set R20 from min R2eff in preparation for Grid search. 6606 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6607 6608 # Check and print parameters. 6609 if True: 6610 # Print for pipe name 6611 method = methods[0] 6612 glob_ini = list_glob_ini[0] 6613 6614 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup', glob_ini=glob_ini) 6615 RDR.spin_display_params(pipe_name=test_pipe_name) 6616 6617 # Then Grid search. 6618 if True: 6619 # Do Grid search. 6620 RDR.minimise_grid_search(inc=200, verbosity=1, methods=methods, model=MODEL_CR72, analysis='grid', analysis_from='grid_setup', list_glob_ini=list_glob_ini, force=True) 6621 6622 # Then cluster spins. 6623 if True: 6624 RDR.cluster_spins(spin_id=selection, methods=methods, model=MODEL_CR72, analysis='grid', list_glob_ini=list_glob_ini, force=True) 6625 6626 # Then Minimise. 6627 if True: 6628 # Minimise 6629 RDR.opt_max_iterations = int(1e2) 6630 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min', analysis_from='grid', list_glob_ini=list_glob_ini, force=False) 6631 6632 # Plot statistics. 6633 # Try plot some minimisation correlations. 6634 if True: 6635 selection = ':2,3' 6636 # Collect param values. 6637 analysis = 'min' 6638 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6639 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6640 6641 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]] 6642 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]] 6643 corr_data = [fig1, fig2] 6644 6645 write_stats = True 6646 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6647 6648 # Open stat file. 6649 if write_stats: 6650 for i, corr_data_i in enumerate(corr_data): 6651 data, methods, glob_inis = corr_data[i] 6652 data_x, data_y = data 6653 method_x, method_y = methods 6654 glob_ini_x, glob_ini_y = glob_inis 6655 6656 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y) 6657 6658 if selection == None: 6659 file_name = file_name_ini + '_all.txt' 6660 else: 6661 file_name = file_name_ini + '_sel.txt' 6662 path = RDR.results_dir 6663 data = extract_data(file=file_name, dir=path) 6664 6665 # Loop over the lines. 6666 for i, data_i in enumerate(data): 6667 print(i, data_i) 6668 6669 # Try plot some minimisation statistics. 6670 if True: 6671 # Collect param values. 6672 selections = [':2,3'] 6673 for selection in selections: 6674 analysis = 'min' 6675 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6676 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6677 6678 # Get param stats. 6679 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126]) 6680 6681 ## Plot R2eff stats 6682 write_stats = True 6683 RDR.plot_min_stat(min_stat_dic=min_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6684 6685 # Open stat file. 6686 if write_stats: 6687 if selection == None: 6688 file_name = '%s_stat_all.txt' % (analysis) 6689 else: 6690 file_name = '%s_stat_sel.txt' % (analysis) 6691 path = RDR.results_dir 6692 data = extract_data(file=file_name, dir=path) 6693 6694 # Loop over the lines. 6695 for i, data_i in enumerate(data): 6696 print(i, data_i)
6697 6698 6699
6700 - def test_r1rho_kjaergaard_auto(self):
6701 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 6702 6703 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 6704 6705 This uses the automatic analysis. 6706 6707 """ 6708 6709 # Cluster residues 6710 cluster_ids = [ 6711 ":13@N", 6712 ":15@N", 6713 ":16@N", 6714 ":25@N", 6715 ":26@N", 6716 ":28@N", 6717 ":39@N", 6718 ":40@N", 6719 ":41@N", 6720 ":43@N", 6721 ":44@N", 6722 ":45@N", 6723 ":49@N", 6724 ":52@N", 6725 ":53@N"] 6726 6727 # Load the data. 6728 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 6729 6730 # Test some of the sequence. 6731 self.assertEqual(len(cdp.mol), 1) 6732 self.assertEqual(cdp.mol[0].name, None) 6733 self.assertEqual(len(cdp.mol[0].res), 48) 6734 6735 # Test the chemical shift data. 6736 cs = [122.223, 122.162, 114.250, 125.852, 118.626, 117.449, 119.999, 122.610, 118.602, 118.291, 115.393, 6737 121.288, 117.448, 116.378, 116.316, 117.263, 122.211, 118.748, 118.103, 119.421, 119.317, 119.386, 117.279, 6738 122.103, 120.038, 116.698, 111.811, 118.639, 118.285, 121.318, 117.770, 119.948, 119.759, 118.314, 118.160, 6739 121.442, 118.714, 113.080, 125.706, 119.183, 120.966, 122.361, 126.675, 117.069, 120.875, 109.372, 119.811, 126.048] 6740 6741 i = 0 6742 for spin, spin_id in spin_loop(return_id=True): 6743 # Check the chemical shift. 6744 self.assertEqual(spin.chemical_shift, cs[i]) 6745 6746 # Increment the index. 6747 i += 1 6748 6749 # Initialize counter 6750 i = 0 6751 j = 0 6752 # Count instances of select/deselect 6753 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 6754 if curspin.select == True: 6755 i += 1 6756 if curspin.select == False: 6757 j += 1 6758 6759 # Test number of selected/deselected spins. 6760 self.assertEqual(i, len(cluster_ids)) 6761 self.assertEqual(j, 48-len(cluster_ids)) 6762 6763 # Check the initial setup. 6764 self.assertEqual(cdp.mol[0].res[7].num, 13) 6765 self.assertEqual(cdp.mol[0].res[7].spin[0].kex, ds.guess[':13@N'][6]) 6766 self.assertEqual(cdp.mol[0].res[7].spin[0].ri_data['R1'], ds.ref[':13@N'][2]) 6767 6768 self.assertEqual(cdp.mol[0].res[9].num, 15) 6769 self.assertEqual(cdp.mol[0].res[9].spin[0].kex, ds.guess[':15@N'][6]) 6770 self.assertEqual(cdp.mol[0].res[9].spin[0].ri_data['R1'], ds.ref[':15@N'][2]) 6771 6772 self.assertEqual(cdp.mol[0].res[10].num, 16) 6773 self.assertEqual(cdp.mol[0].res[10].spin[0].kex, ds.guess[':16@N'][6]) 6774 self.assert_(hasattr(cdp.mol[0].res[10].spin[0], 'ri_data')) 6775 6776 self.assertEqual(cdp.mol[0].res[16].num, 25) 6777 self.assertEqual(cdp.mol[0].res[16].spin[0].kex, ds.guess[':25@N'][6]) 6778 self.assert_(hasattr(cdp.mol[0].res[16].spin[0], 'ri_data')) 6779 6780 self.assertEqual(cdp.mol[0].res[17].num, 26) 6781 self.assertEqual(cdp.mol[0].res[17].spin[0].kex, ds.guess[':26@N'][6]) 6782 self.assert_(hasattr(cdp.mol[0].res[17].spin[0], 'ri_data')) 6783 6784 self.assertEqual(cdp.mol[0].res[19].num, 28) 6785 self.assertEqual(cdp.mol[0].res[19].spin[0].kex, ds.guess[':28@N'][6]) 6786 self.assert_(hasattr(cdp.mol[0].res[19].spin[0], 'ri_data')) 6787 6788 self.assertEqual(cdp.mol[0].res[29].num, 39) 6789 self.assertEqual(cdp.mol[0].res[29].spin[0].kex, ds.guess[':39@N'][6]) 6790 self.assert_(hasattr(cdp.mol[0].res[29].spin[0], 'ri_data')) 6791 6792 self.assertEqual(cdp.mol[0].res[30].num, 40) 6793 self.assertEqual(cdp.mol[0].res[30].spin[0].kex, ds.guess[':40@N'][6]) 6794 self.assert_(hasattr(cdp.mol[0].res[30].spin[0], 'ri_data')) 6795 6796 self.assertEqual(cdp.mol[0].res[31].num, 41) 6797 self.assertEqual(cdp.mol[0].res[31].spin[0].kex, ds.guess[':41@N'][6]) 6798 self.assert_(hasattr(cdp.mol[0].res[31].spin[0], 'ri_data')) 6799 6800 self.assertEqual(cdp.mol[0].res[33].num, 43) 6801 self.assertEqual(cdp.mol[0].res[33].spin[0].kex, ds.guess[':43@N'][6]) 6802 self.assert_(hasattr(cdp.mol[0].res[33].spin[0], 'ri_data')) 6803 6804 self.assertEqual(cdp.mol[0].res[34].num, 44) 6805 self.assertEqual(cdp.mol[0].res[34].spin[0].kex, ds.guess[':44@N'][6]) 6806 self.assert_(hasattr(cdp.mol[0].res[34].spin[0], 'ri_data')) 6807 6808 self.assertEqual(cdp.mol[0].res[35].num, 45) 6809 self.assertEqual(cdp.mol[0].res[35].spin[0].kex, ds.guess[':45@N'][6]) 6810 self.assert_(hasattr(cdp.mol[0].res[35].spin[0], 'ri_data')) 6811 6812 self.assertEqual(cdp.mol[0].res[38].num, 49) 6813 self.assertEqual(cdp.mol[0].res[38].spin[0].kex, ds.guess[':49@N'][6]) 6814 self.assert_(hasattr(cdp.mol[0].res[38].spin[0], 'ri_data')) 6815 6816 self.assertEqual(cdp.mol[0].res[41].num, 52) 6817 self.assertEqual(cdp.mol[0].res[41].spin[0].kex, ds.guess[':52@N'][6]) 6818 self.assert_(hasattr(cdp.mol[0].res[41].spin[0], 'ri_data')) 6819 6820 self.assertEqual(cdp.mol[0].res[42].num, 53) 6821 self.assertEqual(cdp.mol[0].res[42].spin[0].kex, ds.guess[':53@N'][6]) 6822 self.assert_(hasattr(cdp.mol[0].res[42].spin[0], 'ri_data')) 6823 6824 # The dispersion models. 6825 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 6826 6827 # The grid search size (the number of increments per dimension). 6828 GRID_INC = 4 6829 6830 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 6831 MC_NUM = 3 6832 6833 # Model selection technique. 6834 MODSEL = 'AIC' 6835 6836 # Execute the auto-analysis (fast). 6837 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 6838 OPT_FUNC_TOL = 1e-1 6839 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 6840 OPT_MAX_ITERATIONS = 1000 6841 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 6842 6843 result_dir_name = ds.tmpdir 6844 6845 # Make all spins free 6846 for curspin in cluster_ids: 6847 self.interpreter.relax_disp.cluster('free spins', curspin) 6848 # Shut them down 6849 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 6850 6851 # Select only a subset of spins for global fitting 6852 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 6853 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 6854 6855 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 6856 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 6857 6858 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 6859 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 6860 6861 # Run the analysis. 6862 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 6863 6864 # Check the kex value of residue 52 6865 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 6866 6867 # Print results for each model. 6868 print("\n\n################") 6869 print("Printing results") 6870 print("################\n") 6871 for model in MODELS: 6872 # Skip R2eff model. 6873 if model == MODEL_R2EFF: 6874 continue 6875 6876 # Switch to pipe. 6877 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 6878 print("\nModel: %s" % (model)) 6879 6880 # Loop over the spins. 6881 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6882 # Generate spin string. 6883 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 6884 6885 # Loop over the parameters. 6886 print("Optimised parameters for spin: %s" % (spin_string)) 6887 for param in cur_spin.params + ['chi2']: 6888 # Get the value. 6889 if param in ['r1', 'r2']: 6890 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 6891 # Generate the R20 key. 6892 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 6893 6894 # Get the value. 6895 value = getattr(cur_spin, param)[r20_key] 6896 6897 # Print value. 6898 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 6899 6900 # For all other parameters. 6901 else: 6902 # Get the value. 6903 value = getattr(cur_spin, param) 6904 6905 # Print value. 6906 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 6907 6908 # Print the final pipe. 6909 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % ('final')) 6910 print("\nFinal pipe")
6911 6912
6914 """Check of plot_disp_curves() function, after optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'R2eff' model. 6915 6916 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 6917 6918 This uses the automatic analysis. 6919 6920 """ 6921 6922 # Cluster residues 6923 cluster_ids = [ 6924 ":52@N"] 6925 6926 # Load the data. 6927 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 6928 6929 # The dispersion models. 6930 MODELS = [MODEL_R2EFF] 6931 6932 # The grid search size (the number of increments per dimension). 6933 GRID_INC = 4 6934 6935 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 6936 MC_NUM = 3 6937 6938 # Model selection technique. 6939 MODSEL = 'AIC' 6940 6941 # Execute the auto-analysis (fast). 6942 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 6943 OPT_FUNC_TOL = 1e-1 6944 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 6945 OPT_MAX_ITERATIONS = 1000 6946 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 6947 6948 result_dir_name = ds.tmpdir 6949 6950 # Make all spins free 6951 for curspin in cluster_ids: 6952 self.interpreter.relax_disp.cluster('free spins', curspin) 6953 # Shut them down 6954 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 6955 6956 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 6957 6958 # Run the analysis. 6959 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 6960 6961 # Check the graphs produced. 6962 graph_comb = [ 6963 [Y_AXIS_R2_EFF, X_AXIS_DISP, INTERPOLATE_DISP], 6964 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_DISP], 6965 [Y_AXIS_R2_R1RHO, X_AXIS_W_EFF, INTERPOLATE_DISP], 6966 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_OFFSET] 6967 ] 6968 6969 # Define expected folder names. 6970 result_folders = MODELS 6971 6972 # Assign spin_id. 6973 spin_id = ':52@N' 6974 6975 # Loop over result folders. 6976 for result_folder in result_folders: 6977 # Skip the model R2eff, which does not produce graphs. 6978 if result_folder == MODEL_R2EFF: 6979 continue 6980 6981 # Loop over graphs. 6982 for y_axis, x_axis, interpolate in graph_comb: 6983 # Determine file name: 6984 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 6985 6986 # Make the file name. 6987 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 6988 6989 # Get the file path. 6990 file_path = get_file_path(file_name, result_dir_name+sep+result_folder) 6991 6992 print("Testing file access to graph: %s"%file_path) 6993 self.assert_(access(file_path, F_OK)) 6994 6995 # Start testing all possible combinations of graphs. 6996 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 6997 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 6998 interpolate_types = [INTERPOLATE_DISP, INTERPOLATE_OFFSET] 6999 7000 result_dir_name = ds.tmpdir 7001 7002 # Loop through all possible combinations of y_axis, x_axis and interpolation. 7003 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep+'check_graphs' 7004 7005 for result_folder in result_folders: 7006 # Skip the model R2eff, which does not produce graphs. 7007 if result_folder == MODEL_R2EFF: 7008 continue 7009 7010 for y_axis in y_axis_types: 7011 for x_axis in x_axis_types: 7012 for interpolate in interpolate_types: 7013 # Determine file name: 7014 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 7015 7016 # Make the file name. 7017 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 7018 7019 # Write the curves. 7020 dir = result_dir_name+sep+result_folder 7021 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 7022 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 7023 7024 # Get the file path. 7025 file_path = get_file_path(file_name, dir) 7026 7027 # Test the plot file exists. 7028 print("Testing file access to graph: %s"%file_path) 7029 self.assert_(access(file_path, F_OK)) 7030 7031 # Now open, and compare content, line by line. 7032 file_prod = open(file_path) 7033 lines_prod = file_prod.readlines() 7034 file_prod.close() 7035 7036 # Define file to compare against. 7037 dir_comp = data_path+sep+result_folder 7038 file_path_comp = get_file_path(file_name, dir_comp) 7039 file_comp = open(file_path_comp) 7040 lines_comp = file_comp.readlines() 7041 file_comp.close() 7042 7043 # Assert number of lines is equal. 7044 self.assertEqual(len(lines_prod), len(lines_comp)) 7045 for j in range(len(lines_prod)): 7046 # Make the string test 7047 first_char = lines_prod[j][0] 7048 if first_char in ["@", "&"]: 7049 self.assertEqual(lines_prod[j], lines_comp[j]) 7050 else: 7051 # Split string in x, y, error. 7052 # The error would change per run. 7053 x_prod, y_prod, y_prod_err = lines_prod[j].split() 7054 x_comp, y_comp, y_comp_err = lines_comp[j].split() 7055 self.assertAlmostEqual(float(x_prod), float(x_comp)) 7056 self.assertAlmostEqual(float(y_prod), float(y_comp))
7057 7058
7060 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 7061 7062 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 7063 7064 This uses the automatic analysis, with missing loading R1. 7065 7066 """ 7067 7068 # Cluster residues 7069 cluster_ids = [ 7070 ":13@N", 7071 ":15@N", 7072 ":16@N", 7073 ":25@N", 7074 ":26@N", 7075 ":28@N", 7076 ":39@N", 7077 ":40@N", 7078 ":41@N", 7079 ":43@N", 7080 ":44@N", 7081 ":45@N", 7082 ":49@N", 7083 ":52@N", 7084 ":53@N"] 7085 7086 # Load the data. 7087 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 7088 7089 # The dispersion models. 7090 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 7091 7092 # The grid search size (the number of increments per dimension). 7093 GRID_INC = None 7094 7095 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7096 MC_NUM = 3 7097 7098 # Model selection technique. 7099 MODSEL = 'AIC' 7100 7101 # Execute the auto-analysis (fast). 7102 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7103 OPT_FUNC_TOL = 1e-25 7104 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7105 OPT_MAX_ITERATIONS = 10000000 7106 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7107 7108 result_dir_name = ds.tmpdir 7109 7110 # Make all spins free 7111 for curspin in cluster_ids: 7112 self.interpreter.relax_disp.cluster('free spins', curspin) 7113 # Shut them down 7114 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 7115 7116 # Select only a subset of spins for global fitting 7117 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 7118 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 7119 7120 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 7121 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 7122 7123 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 7124 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 7125 7126 # Point to directory with R2eff values, with 2000 MC simulations. 7127 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" 7128 7129 r1_fit = True 7130 7131 # Run the analysis. 7132 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, pre_run_dir=prev_data_path, r1_fit=r1_fit) 7133 7134 # Verify the data. 7135 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='MC2000')
7136 7137
7138 - def test_r2eff_read(self):
7139 """Test the operation of the relax_disp.r2eff_read user function.""" 7140 7141 # The path to the data files. 7142 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'800_MHz' 7143 7144 # Read the sequence data. 7145 self.interpreter.sequence.read(file='66.667.in', dir=data_path, res_num_col=1) 7146 7147 # The ID. 7148 id = 'test' 7149 7150 # Set up the metadata. 7151 self.interpreter.spectrometer.frequency(id=id, frq=800e6) 7152 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 7153 7154 # Try reading the file. 7155 self.interpreter.relax_disp.r2eff_read(id=id, file='66.667.in', dir=data_path, disp_frq=66.667, res_num_col=1, data_col=2, error_col=3) 7156 7157 # Check the global data. 7158 data = [ 7159 ['cpmg_frqs', {'test': 66.667}], 7160 ['cpmg_frqs_list', [66.667]], 7161 ['dispersion_points', 1], 7162 ['exp_type', {'test': 'SQ CPMG'}], 7163 ['exp_type_list', ['SQ CPMG']], 7164 ['spectrometer_frq', {'test': 800000000.0}], 7165 ['spectrometer_frq_count', 1], 7166 ['spectrometer_frq_list', [800000000.0]], 7167 ['spectrum_ids', ['test']] 7168 ] 7169 for name, value in data: 7170 # Does it exist? 7171 self.assert_(hasattr(cdp, name)) 7172 7173 # Check the object. 7174 obj = getattr(cdp, name) 7175 self.assertEqual(obj, value) 7176 7177 # Check the spin data. 7178 data = [ 7179 [1, 2.3035747e+04, 8.5467725e+01], 7180 [2, 9.9629762e+04, 2.8322033e+02], 7181 [3, 9.5663137e+04, 2.8632929e+02], 7182 [4, 1.7089893e+05, 3.1089428e+02], 7183 [5, 4.7323876e+04, 1.0084269e+02], 7184 [6, 2.0199122e+04, 1.0135220e+02], 7185 [7, 1.6655488e+05, 3.1609061e+02], 7186 [8, 9.0061074e+04, 1.9176585e+02], 7187 [10, 8.4726204e+04, 2.8898155e+02], 7188 [11, 1.5050233e+05, 4.3138029e+02], 7189 [12, 9.2998531e+04, 3.0440191e+02], 7190 [13, 1.6343507e+05, 3.3144097e+02], 7191 [14, 1.0137301e+05, 3.7314642e+02], 7192 [15, 8.3407837e+04, 1.6546473e+02], 7193 [16, 1.3819126e+05, 3.3388517e+02], 7194 [17, 1.1010490e+05, 3.5639222e+02], 7195 [18, 9.4324035e+04, 3.2343585e+02], 7196 [19, 1.1135179e+05, 3.0706671e+02], 7197 [20, 7.6339410e+04, 1.7377460e+02], 7198 [21, 6.2008453e+04, 1.7327150e+02], 7199 [22, 1.0590404e+05, 2.4814635e+02], 7200 [23, 1.0630198e+05, 2.3601100e+02], 7201 [24, 7.2996320e+04, 1.4952465e+02], 7202 [25, 9.5486742e+04, 2.7080766e+02], 7203 [26, 5.8067989e+04, 1.6820462e+02], 7204 [27, -1.7168510e+04, 2.2519560e+02], 7205 [28, 1.6891473e+05, 2.3497525e+02], 7206 [29, 9.4038555e+04, 2.0357593e+02], 7207 [30, 2.1386951e+04, 2.2153532e+02], 7208 [31, 9.3982899e+04, 2.0937056e+02], 7209 [32, 8.6097484e+04, 2.3868467e+02], 7210 [33, 1.0194337e+05, 2.7370704e+02], 7211 [34, 8.5683111e+04, 2.0838076e+02], 7212 [35, 8.6985768e+04, 2.0889310e+02], 7213 [36, 8.6011237e+04, 1.7498390e+02], 7214 [37, 1.0984097e+05, 2.7622998e+02], 7215 [38, 8.7017879e+04, 2.6547994e+02], 7216 [39, 9.1682649e+04, 5.2777676e+02], 7217 [40, 7.6370440e+04, 1.9873214e+02], 7218 [41, 9.1393531e+04, 2.4483824e+02], 7219 [42, 1.1017111e+05, 2.8020699e+02], 7220 [43, 9.4552366e+04, 3.4394150e+02], 7221 [44, 1.2858281e+05, 6.8449252e+02], 7222 [45, 7.4583525e+04, 1.9544210e+02], 7223 [46, 9.2087490e+04, 2.0491066e+02], 7224 [47, 9.7507255e+04, 2.5162839e+02], 7225 [48, 1.0033842e+05, 2.7566430e+02], 7226 [49, 1.3048305e+05, 2.6797466e+02], 7227 [50, 1.0546796e+05, 1.9304384e+02], 7228 [51, 9.3099697e+04, 2.0773311e+02], 7229 [52, 4.6863758e+04, 1.3169068e+02], 7230 [53, 6.1055806e+04, 1.5448477e+02], 7231 [55, 6.8629994e+04, 1.6868673e+02], 7232 [56, 1.1005552e+05, 2.1940465e+02], 7233 [57, 1.0572760e+05, 1.9768486e+02], 7234 [58, 1.1176950e+05, 3.0009610e+02], 7235 [59, 9.8758603e+04, 3.3803895e+02], 7236 [60, 9.9517201e+04, 3.5137994e+02], 7237 [61, 5.4357946e+04, 2.5896579e+02], 7238 [62, 1.0899978e+05, 2.8720371e+02], 7239 [63, 8.4549759e+04, 4.1401837e+02], 7240 [64, 5.5014550e+04, 2.1135781e+02], 7241 [65, 8.0569666e+04, 2.3249709e+02], 7242 [66, 1.2936610e+05, 3.5218725e+02], 7243 [67, 3.6438010e+04, 8.7924003e+01], 7244 [70, 3.8763157e+04, 1.3325040e+02], 7245 [71, 8.5711411e+04, 2.9316183e+02], 7246 [72, 3.3211541e+04, 1.2182123e+02], 7247 [73, 3.2070576e+04, 1.2305430e+02] 7248 ] 7249 for res_num, value, error in data: 7250 # Get the spin. 7251 spin = return_spin(spin_id=":%s"%res_num) 7252 7253 # Check the values. 7254 self.assertEqual(spin.r2eff['sq_cpmg_800.00000000_0.000_66.667'], value) 7255 self.assertEqual(spin.r2eff_err['sq_cpmg_800.00000000_0.000_66.667'], error)
7256 7257
7258 - def test_r2eff_read_spin(self):
7259 """Test the operation of the relax_disp.r2eff_read_spin user function.""" 7260 7261 # The path to the data files. 7262 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 7263 7264 # Generate the sequence. 7265 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 7266 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 7267 self.interpreter.spin.isotope('1H', spin_id='@H') 7268 self.interpreter.spin.isotope('15N', spin_id='@N') 7269 7270 # Build the experiment IDs. 7271 H_disp_points = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0] 7272 N_disp_points = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 7273 ids = [] 7274 for value in H_disp_points: 7275 ids.append('1H_CPMG_%s' % value) 7276 for value in N_disp_points: 7277 ids.append('15N_CPMG_%s' % value) 7278 print("\n\nThe experiment IDs are %s." % ids) 7279 7280 # Set up the metadata for the experiments. 7281 for id in ids: 7282 self.interpreter.spectrometer.frequency(id=id, frq=500e6) 7283 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 7284 for value in H_disp_points: 7285 self.interpreter.relax_disp.cpmg_setup(spectrum_id='1H_CPMG_%s' % value, cpmg_frq=value) 7286 for value in N_disp_points: 7287 self.interpreter.relax_disp.cpmg_setup(spectrum_id='15N_CPMG_%s' % value, cpmg_frq=value) 7288 7289 # Loop over the experiments. 7290 for id, file, spin_id in [['1H_CPMG', 'hs_500.res', ':9@H'], ['15N_CPMG', 'ns_500.res', ':9@N']]: 7291 # Try reading the file. 7292 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3) 7293 7294 # Check the global data. 7295 data = [ 7296 ['cpmg_frqs', {'1H_CPMG_667.0': 667.0, '1H_CPMG_1067.0': 1067.0, '15N_CPMG_350.0': 350.0, '1H_CPMG_933.0': 933.0, '15N_CPMG_50.0': 50.0, '15N_CPMG_100.0': 100.0, '1H_CPMG_400.0': 400.0, '1H_CPMG_533.0': 533.0, '1H_CPMG_800.0': 800.0, '15N_CPMG_900.0': 900.0, '15N_CPMG_150.0': 150.0, '15N_CPMG_800.0': 800.0, '1H_CPMG_267.0': 267.0, '1H_CPMG_2667.0': 2667.0, '15N_CPMG_300.0': 300.0, '1H_CPMG_133.0': 133.0, '15N_CPMG_700.0': 700.0, '1H_CPMG_67.0': 67.0, '15N_CPMG_400.0': 400.0, '15N_CPMG_250.0': 250.0, '1H_CPMG_2133.0': 2133.0, '1H_CPMG_1600.0': 1600.0, '15N_CPMG_200.0': 200.0, '15N_CPMG_1000.0': 1000.0, '15N_CPMG_500.0': 500.0, '15N_CPMG_600.0': 600.0}], 7297 ['cpmg_frqs_list', [50.0, 67.0, 100.0, 133.0, 150.0, 200.0, 250.0, 267.0, 300.0, 350.0, 400.0, 500.0, 533.0, 600.0, 667.0, 700.0, 800.0, 900.0, 933.0, 1000.0, 1067.0, 1600.0, 2133.0, 2667.0]], 7298 ['dispersion_points', 24], 7299 ['exp_type', {'1H_CPMG_667.0': 'SQ CPMG', '1H_CPMG_1067.0': 'SQ CPMG', '15N_CPMG_350.0': 'SQ CPMG', '1H_CPMG_933.0': 'SQ CPMG', '15N_CPMG_50.0': 'SQ CPMG', '15N_CPMG_100.0': 'SQ CPMG', '1H_CPMG_400.0': 'SQ CPMG', '1H_CPMG_533.0': 'SQ CPMG', '1H_CPMG_800.0': 'SQ CPMG', '15N_CPMG_900.0': 'SQ CPMG', '15N_CPMG_150.0': 'SQ CPMG', '15N_CPMG_800.0': 'SQ CPMG', '1H_CPMG_267.0': 'SQ CPMG', '1H_CPMG_2667.0': 'SQ CPMG', '15N_CPMG_300.0': 'SQ CPMG', '1H_CPMG_133.0': 'SQ CPMG', '15N_CPMG_700.0': 'SQ CPMG', '1H_CPMG_67.0': 'SQ CPMG', '15N_CPMG_400.0': 'SQ CPMG', '15N_CPMG_250.0': 'SQ CPMG', '1H_CPMG_2133.0': 'SQ CPMG', '1H_CPMG_1600.0': 'SQ CPMG', '15N_CPMG_200.0': 'SQ CPMG', '15N_CPMG_1000.0': 'SQ CPMG', '15N_CPMG_500.0': 'SQ CPMG', '15N_CPMG_600.0': 'SQ CPMG'}], 7300 ['exp_type_list', ['SQ CPMG']], 7301 ['spectrometer_frq', {'1H_CPMG_667.0': 500000000.0, '1H_CPMG_1067.0': 500000000.0, '15N_CPMG_350.0': 500000000.0, '1H_CPMG_933.0': 500000000.0, '15N_CPMG_50.0': 500000000.0, '15N_CPMG_100.0': 500000000.0, '1H_CPMG_400.0': 500000000.0, '1H_CPMG_533.0': 500000000.0, '1H_CPMG_800.0': 500000000.0, '15N_CPMG_900.0': 500000000.0, '15N_CPMG_150.0': 500000000.0, '15N_CPMG_800.0': 500000000.0, '1H_CPMG_267.0': 500000000.0, '1H_CPMG_2667.0': 500000000.0, '15N_CPMG_300.0': 500000000.0, '1H_CPMG_133.0': 500000000.0, '15N_CPMG_700.0': 500000000.0, '1H_CPMG_67.0': 500000000.0, '15N_CPMG_400.0': 500000000.0, '15N_CPMG_250.0': 500000000.0, '1H_CPMG_2133.0': 500000000.0, '1H_CPMG_1600.0': 500000000.0, '15N_CPMG_200.0': 500000000.0, '15N_CPMG_1000.0': 500000000.0, '15N_CPMG_500.0': 500000000.0, '15N_CPMG_600.0': 500000000.0}], 7302 ['spectrometer_frq_count', 1], 7303 ['spectrometer_frq_list', [500000000.0]], 7304 ['spectrum_ids', ['1H_CPMG_67.0', '1H_CPMG_133.0', '1H_CPMG_267.0', '1H_CPMG_400.0', '1H_CPMG_533.0', '1H_CPMG_667.0', '1H_CPMG_800.0', '1H_CPMG_933.0', '1H_CPMG_1067.0', '1H_CPMG_1600.0', '1H_CPMG_2133.0', '1H_CPMG_2667.0', '15N_CPMG_50.0', '15N_CPMG_100.0', '15N_CPMG_150.0', '15N_CPMG_200.0', '15N_CPMG_250.0', '15N_CPMG_300.0', '15N_CPMG_350.0', '15N_CPMG_400.0', '15N_CPMG_500.0', '15N_CPMG_600.0', '15N_CPMG_700.0', '15N_CPMG_800.0', '15N_CPMG_900.0', '15N_CPMG_1000.0']] 7305 ] 7306 for name, value in data: 7307 # Does it exist? 7308 self.assert_(hasattr(cdp, name)) 7309 7310 # Check the object. 7311 obj = getattr(cdp, name) 7312 if not isinstance(data, dict): 7313 self.assertEqual(obj, value) 7314 7315 # Check the global dictionary data. 7316 else: 7317 for id in ids: 7318 self.assertEqual(obj[id], value[id]) 7319 7320 # Check the spin data. 7321 h_data = [ 7322 [ 67.0, 21.47924, 0.42958], 7323 [ 133.0, 16.73898, 0.33478], 7324 [ 267.0, 9.97357, 0.19947], 7325 [ 400.0, 8.23877, 0.24737], 7326 [ 533.0, 7.59290, 0.24263], 7327 [ 667.0, 7.45843, 0.24165], 7328 [ 800.0, 7.11222, 0.23915], 7329 [ 933.0, 7.40880, 0.24129], 7330 [1067.0, 6.55191, 0.16629], 7331 [1600.0, 6.72177, 0.23637], 7332 [2133.0, 7.09629, 0.23904], 7333 [2667.0, 7.14675, 0.23940] 7334 ] 7335 for disp_point, value, error in h_data: 7336 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 7337 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 7338 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 7339 n_data = [ 7340 [ 50.0, 27.15767, 0.54315], 7341 [ 100.0, 26.55781, 0.53116], 7342 [ 150.0, 24.73462, 0.49469], 7343 [ 200.0, 20.98617, 0.41972], 7344 [ 250.0, 17.82442, 0.35649], 7345 [ 300.0, 15.55352, 0.31107], 7346 [ 350.0, 13.78958, 0.27579], 7347 [ 400.0, 12.48334, 0.24967], 7348 [ 500.0, 11.55724, 0.23114], 7349 [ 600.0, 10.53874, 0.21077], 7350 [ 700.0, 10.07395, 0.20148], 7351 [ 800.0, 9.62952, 0.19259], 7352 [ 900.0, 9.49994, 0.19000], 7353 [1000.0, 8.71350, 0.17427] 7354 ] 7355 for disp_point, value, error in n_data: 7356 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 7357 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff[id], value) 7358 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff_err[id], error)
7359 7360
7361 - def test_r2eff_fit_fixed_time(self):
7362 """Test the relaxation dispersion 'R2eff' model for fixed time data in the auto-analysis.""" 7363 7364 # Execute the script. 7365 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r2eff_calc.py')
7366 7367
7368 - def test_read_r2eff(self):
7369 """Test the reading of a file containing r2eff values.""" 7370 7371 # Create the sequence data, and name the spins. 7372 self.interpreter.residue.create(1, 'Gly') 7373 self.interpreter.residue.create(2, 'Gly') 7374 self.interpreter.residue.create(3, 'Gly') 7375 7376 # Read the file. 7377 self.interpreter.relax_data.read(ri_id='R2eff.600', ri_type='R2eff', frq=600*1e6, file='r2eff.out', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r2eff', res_num_col=1, res_name_col=2, data_col=3, error_col=4) 7378 7379 # Test the data. 7380 self.assertEqual(cdp.mol[0].res[0].spin[0].ri_data['R2eff.600'], 15.000) 7381 self.assertEqual(cdp.mol[0].res[1].spin[0].ri_data['R2eff.600'], 4.2003) 7382 self.assertEqual(cdp.mol[0].res[2].spin[0].ri_data['R2eff.600'], 7.2385)
7383 7384
7386 """Test speeding up grid search. Support requst sr #3151 U{https://gna.org/support/index.php?3151}. 7387 7388 User function to set the R20 parameters in the default grid search using the minimum R2eff value. 7389 7390 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7391 'SOD1-WT' CPMG data to the CR72 dispersion model. 7392 7393 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7394 Data is for experiment at 25 degree Celcius. 7395 """ 7396 7397 # Base data setup. 7398 pipe_name = 'base pipe' 7399 pipe_type = 'relax_disp' 7400 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7401 select_spin_index = list(range(0, 1)) 7402 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7403 7404 # Generate r20 key. 7405 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7406 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7407 7408 ## Now prepare for MODEL calculation. 7409 MODEL = "CR72" 7410 7411 # Change pipe. 7412 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 7413 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7414 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7415 7416 # Then select model. 7417 self.interpreter.relax_disp.select_model(model=MODEL) 7418 7419 # Set the R20 parameters in the default grid search using the minimum R2eff value. 7420 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 7421 7422 # Test result, for normal run. 7423 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7424 # Get the spin_params. 7425 spin_params = spin.params 7426 7427 # Defined fixed values for testing. 7428 if spin_id == ":10@N": 7429 self.assertEqual(spin.r2[r20_key_600], 20.282732526087106) 7430 self.assertEqual(spin.r2[r20_key_500], 18.475299724356649) 7431 7432 # Print out. 7433 print("r2_600=%2.2f r2_500=%2.2f spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin_id, resi, resn)) 7434 7435 # Testing the r2 values for the different fields are not the same. 7436 self.assert_(spin.r2[r20_key_600] != spin.r2[r20_key_500]) 7437 7438 # Test values are larger than 0. 7439 self.assert_(spin.r2[r20_key_600] > 0.0) 7440 self.assert_(spin.r2[r20_key_500] > 0.0) 7441 7442 # Loop over the experiment settings. 7443 r2eff_600 = [] 7444 r2eff_500 = [] 7445 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 7446 # Create the data key. 7447 data_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 7448 7449 # Extract the r2 eff data. 7450 r2eff = spin.r2eff[data_key] 7451 if frq == 599.8908617*1E6: 7452 r2eff_600.append(r2eff) 7453 elif frq == 499.862139*1E6: 7454 r2eff_500.append(r2eff) 7455 7456 # Sort values. 7457 r2eff_600.sort() 7458 r2eff_500.sort() 7459 7460 # Test values again. 7461 print("For r20 600MHz min r2eff=%3.3f."%(min(r2eff_600))) 7462 print(r2eff_600) 7463 self.assertEqual(spin.r2[r20_key_600], min(r2eff_600)) 7464 print("") 7465 7466 print("For r20 500MHz min r2eff=%3.3f."%(min(r2eff_500))) 7467 print(r2eff_500) 7468 self.assertEqual(spin.r2[r20_key_500], min(r2eff_500)) 7469 print("") 7470 7471 print("###########################################") 7472 print("Trying GRID SEARCH for minimum R2eff values") 7473 7474 ### Test just the Grid search. 7475 GRID_INC = 5 7476 7477 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7478 7479 ### Then test the value.set function. 7480 # Change pipe. 7481 pipe_name_MODEL = "%s_%s_2"%(pipe_name, MODEL) 7482 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7483 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7484 7485 # Then select model. 7486 self.interpreter.relax_disp.select_model(model=MODEL) 7487 7488 # Then set the standard parameter values. 7489 for param in spin_params: 7490 print("Setting standard parameter for param: %s"%param) 7491 self.interpreter.value.set(param=param, index=None) 7492 7493 # Test result, for normal run. 7494 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7495 # Print out. 7496 print("r2_600=%2.2f r2_500=%2.2f pA=%2.2f, dw=%2.2f, kex=%2.2f, spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin.pA, spin.dw, spin.kex, spin_id, resi, resn)) 7497 7498 # Testing the r2 values. 7499 self.assertEqual(spin.r2[r20_key_600], 10.00) 7500 self.assertEqual(spin.r2[r20_key_500], 10.00) 7501 self.assertEqual(spin.pA, 0.9) 7502 self.assertEqual(spin.dw, 1.0) 7503 self.assertEqual(spin.kex, 1000.0) 7504 7505 print("###########################################") 7506 print("Trying GRID SEARCH for standard R2eff values") 7507 7508 ### Test just the Grid search. 7509 GRID_INC = 5 7510 7511 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7512 7513 ### Run auto_analysis. 7514 # The grid search size (the number of increments per dimension). 7515 GRID_INC = 5 7516 7517 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7518 MC_NUM = 3 7519 7520 # Model selection technique. 7521 MODSEL = 'AIC' 7522 7523 # Execute the auto-analysis (fast). 7524 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7525 OPT_FUNC_TOL = 1e-1 7526 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7527 OPT_MAX_ITERATIONS = 1000 7528 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7529 7530 # Run the analysis. 7531 relax_disp.Relax_disp(pipe_name=pipe_name_r2eff, results_dir=ds.tmpdir, models=[MODEL], grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, set_grid_r20=True)
7532 7533
7534 - def test_show_apod_extract(self):
7535 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod.""" 7536 7537 # The path to the data files. 7538 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7539 7540 # Define file name. 7541 file_name = '128_0_FT.ft2' 7542 7543 # Call function. 7544 get_output = show_apod_extract(file_name=file_name, dir=data_path) 7545 7546 # Define how output should look like. 7547 # The output from showApod differs slightly according to NMRPipe version. But 'Noise Std Dev' is the same. 7548 # Dont test lines which can differ. 7549 show_apod_ver = [ 7550 'REMARK Effect of Processing on Peak Parameters and Noise for %s'%(data_path+sep+file_name), 7551 'REMARK Automated Noise Std Dev in Processed Data: 8583.41', 7552 'REMARK Noise Std Dev Before Processing H1 and N15: 60.6558', 7553 '', 7554 'VARS AXIS LABEL TSIZE FSIZE LW_ADJ LW_FINAL HI_FACTOR VOL_FACTOR SIGMA_FACTOR', 7555 'FORMAT %s %-8s %4d %4d %7.4f %7.4f %.4e %.4e %.4e'] 7556 #'', 7557 #' X H1 800 2048 0.8107 3.7310 4.9903e-03 9.8043e-04 5.2684e-02', 7558 #' Y N15 128 256 0.7303 3.0331 3.1260e-02 7.8434e-03 1.3413e-01'] 7559 7560 for i, line in enumerate(show_apod_ver): 7561 line_ver = get_output[i] 7562 7563 print(line) 7564 if line[:50] == 'REMARK Noise Std Dev Before Processing H1 and N15:': 7565 continue 7566 # Make the string test 7567 self.assertEqual(line, line_ver)
7568 7569
7570 - def test_show_apod_rmsd(self):
7571 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod.""" 7572 7573 # The path to the data files. 7574 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7575 7576 # Define file name. 7577 file_name = '128_0_FT.ft2' 7578 7579 # Call function. 7580 rmsd = show_apod_rmsd(file_name=file_name, dir=data_path) 7581 7582 # Assert. 7583 self.assertEqual(rmsd, 8583.41)
7584 7585
7587 """Test searching for all NMRPipe spectrum files in dir, call showApod, and write to files.""" 7588 7589 # The path to the data files. 7590 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7591 7592 # Call function, and get all file names. 7593 wfile_paths = show_apod_rmsd_dir_to_files(file_ext='.ft2', dir=data_path, outdir=self.tmpdir) 7594 7595 # Loop over file_paths. 7596 for wfile_path in wfile_paths: 7597 # Open the file. 7598 get_data = extract_data(file=wfile_path) 7599 7600 # Extract line 0, column 0. 7601 test = float(get_data[0][0]) 7602 7603 # Assert. 7604 self.assertEqual(test, 8583.41)
7605 7606
7608 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod, and write to file.""" 7609 7610 # The path to the data files. 7611 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7612 7613 # Define file name. 7614 file_name = '128_0_FT.ft2' 7615 7616 # Call function, and get file name. 7617 wfile_path = show_apod_rmsd_to_file(file_name=file_name, dir=data_path, outdir=self.tmpdir) 7618 7619 # Open the file. 7620 get_data = extract_data(file=wfile_path) 7621 7622 # Extract line 0, column 0. 7623 test = float(get_data[0][0]) 7624 7625 # Assert. 7626 self.assertEqual(test, 8583.41)
7627 7628
7630 """Error analysis of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 7631 7632 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7633 'SOD1-WT' CPMG data to the CR72 dispersion model. 7634 7635 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7636 Data is for experiment at 25 degree Celcius. 7637 7638 bug #21954 U{https://gna.org/bugs/index.php?21954}: Order of spectrum.error_analysis is important. 7639 """ 7640 7641 # Base data setup. 7642 pipe_name = 'base pipe' 7643 pipe_type = 'relax_disp' 7644 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7645 select_spin_index = list(range(0, 1)) 7646 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7647 7648 # Define replicated 7649 repl_A = ['Z_A1', 'Z_A15'] 7650 repl_B = ['Z_B1', 'Z_B18'] 7651 7652 # Loop over spectrum ID, and sort them 7653 spectrum_ids_A = [] 7654 spectrum_ids_B = [] 7655 for spectrum_id in cdp.spectrum_ids: 7656 if "A" in spectrum_id: 7657 spectrum_ids_A.append(spectrum_id) 7658 elif "B" in spectrum_id: 7659 spectrum_ids_B.append(spectrum_id) 7660 7661 # To clean up old error analysis, delete attributes 7662 delattr(cdp, "var_I") 7663 delattr(cdp, "sigma_I") 7664 7665 # Perform error analysis 7666 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 7667 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 7668 7669 # Loop over spins, save errors to list 7670 Errors_A_B = [] 7671 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7672 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 7673 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 7674 Errors_A_B.append([A_err, B_err]) 7675 7676 # To clean up old error analysis, delete attributes 7677 delattr(cdp, "var_I") 7678 delattr(cdp, "sigma_I") 7679 7680 # Perform error analysis. Order is important 7681 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 7682 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 7683 7684 # Loop over spins, save errors to list 7685 Errors_B_A = [] 7686 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7687 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 7688 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 7689 Errors_B_A.append([A_err, B_err]) 7690 7691 # Make test for order of error 7692 for i in range(len(Errors_A_B)): 7693 Error_A_B = Errors_A_B[i] 7694 Error_B_A = Errors_B_A[i] 7695 self.assertAlmostEqual(Error_A_B[0], Error_B_A[0], 4) 7696 self.assertAlmostEqual(Error_A_B[1], Error_B_A[1], 4) 7697 7698 # Make further tests for fixed values 7699 std_A = math.sqrt((cdp.var_I[repl_A[0]] + cdp.var_I[repl_A[1]])/2) 7700 std_A_fix = 2785.7263335738567 7701 7702 for id_A in spectrum_ids_A: 7703 self.assertEqual(cdp.sigma_I[id_A], std_A) 7704 self.assertAlmostEqual(cdp.sigma_I[id_A], std_A_fix, 7) 7705 7706 std_B = math.sqrt((cdp.var_I[repl_B[0]] + cdp.var_I[repl_B[1]])/2) 7707 std_B_fix = 4967.3772030667988 7708 7709 for id_B in spectrum_ids_B: 7710 self.assertEqual(cdp.sigma_I[id_B], std_B) 7711 self.assertAlmostEqual(cdp.sigma_I[id_B], std_B_fix, 7)
7712 7713
7714 - def test_sod1wt_t25_to_cr72(self):
7715 """Optimisation of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 7716 7717 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7718 'SOD1-WT' CPMG data to the CR72 dispersion model. 7719 7720 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7721 Data is for experiment at 25 degree Celcius. 7722 """ 7723 7724 # Base data setup. 7725 pipe_name = 'base pipe' 7726 pipe_type = 'relax_disp' 7727 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7728 select_spin_index = list(range(0, 2)) 7729 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7730 7731 # Generate r20 key. 7732 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7733 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7734 7735 ## Now prepare for MODEL calculation. 7736 MODEL = "CR72" 7737 7738 # Change pipe. 7739 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 7740 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7741 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7742 7743 # Then select model. 7744 self.interpreter.relax_disp.select_model(model=MODEL) 7745 7746 # GRID inc of 7 was found to be appropriate not to find pA = 0.5. 7747 GRID_INC = 7 7748 7749 # Store grid and minimisations results. 7750 grid_results = [] 7751 mini_results = [] 7752 clust_results = [] 7753 7754 # Set the R20 parameters in the default grid search using the minimum R2eff value. 7755 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 7756 7757 # Deselect insignificant spins. 7758 self.interpreter.relax_disp.insignificance(level=1.0) 7759 7760 # Perform Grid Search. 7761 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7762 7763 # Store result. 7764 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7765 # Store grid results. 7766 grid_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 7767 7768 ## Now do minimisation. 7769 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7770 set_func_tol = 1e-9 7771 set_max_iter = 100000 7772 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 7773 7774 # Store result. 7775 pA_values = [] 7776 kex_values = [] 7777 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7778 # Store minimisation results. 7779 mini_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 7780 7781 # Store pA values. 7782 pA_values.append(spin.pA) 7783 7784 # Store kex values. 7785 kex_values.append(spin.kex) 7786 7787 print("\n# Now print before and after minimisation.\n") 7788 7789 # Print results. 7790 for i in range(len(grid_results)): 7791 # Get values. 7792 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 7793 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 7794 7795 print("GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 7796 print("MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 7797 7798 ## Prepare for clustering 7799 # Change pipe. 7800 pipe_name_MODEL_CLUSTER = "%s_%s_Cluster"%(pipe_name, MODEL) 7801 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL_CLUSTER) 7802 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL_CLUSTER) 7803 7804 # Then select model. 7805 self.interpreter.relax_disp.select_model(model=MODEL) 7806 7807 # Define cluster id. 7808 cluster_id = 'clust' 7809 7810 # Loop over spins to cluster them. 7811 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7812 self.interpreter.relax_disp.cluster(cluster_id, spin_id) 7813 7814 # Copy over values. 7815 self.interpreter.relax_disp.parameter_copy(pipe_from=pipe_name_MODEL, pipe_to=pipe_name_MODEL_CLUSTER) 7816 7817 # Test the median values is correct 7818 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7819 print(pA_values) 7820 # The the median pA value returned. 7821 self.assertEqual(median(pA_values), spin.pA) 7822 7823 # The the median kex value returned. 7824 self.assertEqual(median(kex_values), spin.kex) 7825 7826 ## Now do minimisation. 7827 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 7828 7829 # Store result. 7830 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7831 # Store clust results. 7832 clust_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 7833 7834 # Store the outcome of the clustering minimisation. 7835 clust_pA = spin.pA 7836 clust_kex = spin.kex 7837 7838 print("\n# Now testing.\n") 7839 7840 # Define results 7841 test_res = {} 7842 test_res[':10@N'] = {} 7843 test_res[':10@N']['r2600'] = 18.429755324773360 7844 test_res[':10@N']['r2500'] = 16.981349161968630 7845 test_res[':10@N']['dw'] = 2.700755859433969 7846 test_res[':10@N']['pA'] = 0.971531659288657 7847 test_res[':10@N']['kex'] = 3831.766337047963134 7848 test_res[':11@N'] = {} 7849 test_res[':11@N']['r2600'] = 18.193409421115213 7850 test_res[':11@N']['r2500'] = 17.308838135567765 7851 test_res[':11@N']['dw'] = 2.706650302761793 7852 test_res[':11@N']['pA'] = 0.971531659288657 7853 test_res[':11@N']['kex'] = 3831.766337047963134 7854 7855 # Then make tests. 7856 for i in range(len(grid_results)): 7857 # Get values. 7858 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 7859 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 7860 c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn = clust_results[i] 7861 7862 print("%s GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 7863 print("%s MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 7864 print("%s Clust r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn)) 7865 7866 # Make tests. 7867 self.assertEqual(clust_pA, c_pA) 7868 self.assertEqual(clust_kex, c_kex) 7869 7870 # Test values. 7871 if c_spin_id in test_res: 7872 self.assertAlmostEqual(c_r2_600, test_res[c_spin_id]['r2600'], 4) 7873 self.assertAlmostEqual(c_r2_500, test_res[c_spin_id]['r2500'], 4) 7874 self.assertAlmostEqual(c_dw, test_res[c_spin_id]['dw'], 3) 7875 self.assertAlmostEqual(c_pA, test_res[c_spin_id]['pA'], 5) 7876 self.assertAlmostEqual(c_kex, test_res[c_spin_id]['kex'], 1)
7877 7878 # Save disp graph to temp. 7879 #self.interpreter.relax_disp.plot_disp_curves(dir="~"+sep+"test", num_points=1000, extend=500.0, force=True). 7880 7881
7883 """Conversion of SOD1-WT CPMG R2eff values into input files for sherekhan. 7884 7885 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7886 'SOD1-WT' CPMG data to the CR72 dispersion model. 7887 7888 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7889 Data is for experiment at 25 degree Celcius. 7890 """ 7891 7892 # Base data setup. 7893 pipe_name = 'base pipe' 7894 pipe_type = 'relax_disp' 7895 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7896 select_spin_index = list(range(0, 2)) 7897 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7898 7899 # Generate r20 key. 7900 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7901 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7902 7903 # Cluster everything, to analyse together. 7904 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-1000") 7905 7906 # Write input 7907 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=ds.tmpdir) 7908 7909 # Check the r2eff set files. 7910 print("\nChecking the R2eff input set files.") 7911 files = [[ds.tmpdir + sep + 'cluster1', 'sherekhan_frq1.in'], [ ds.tmpdir + sep + 'cluster1', 'sherekhan_frq2.in']] 7912 7913 # First check file exists 7914 for dir, file in files: 7915 print(dir+sep+file) 7916 self.assert_(access(dir+sep+file, F_OK)) 7917 7918 # Define how files should look like 7919 data_set_600 = [ 7920 "60.8272464287\n", 7921 "0.06\n", 7922 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 7923 "# G10\n", 7924 " 33.333 26.53556078711 0.5236104771163\n", 7925 " 66.667 25.29735243318 0.48766574122\n", 7926 " 100 25.09470361403 0.4820438864671\n", 7927 " 133.333 25.15603274331 0.4837377286085\n", 7928 " 166.667 24.27213341753 0.4599457904395\n", 7929 " 200 24.00364120328 0.4529773198905\n", 7930 " 266.667 24.03511395168 0.4537880662536\n", 7931 " 300 23.04761040024 0.4291039120557\n", 7932 " 333.333 22.95530300787 0.4268745963972\n", 7933 " 400 23.06158810662 0.4294426293624\n", 7934 " 466.667 22.26799054092 0.4106809618644\n", 7935 " 533.333 21.99851418823 0.4045232104735\n", 7936 " 666.667 21.19651570955 0.3868136173831\n", 7937 " 833.333 20.30938498379 0.3682604887899\n", 7938 " 1000 20.28273252609 0.367719392568\n", 7939 "# D11\n", 7940 " 33.333 24.76520269878 0.5026475808706\n", 7941 " 66.667 24.8773107448 0.5058752916906\n", 7942 " 100 24.90357815239 0.5066348551479\n", 7943 " 133.333 23.7782506151 0.4751950583865\n", 7944 " 166.667 23.68548762076 0.4727017128631\n", 7945 " 200 23.58629651618 0.4700517377679\n", 7946 " 266.667 23.47734671187 0.4671601744044\n", 7947 " 300 24.08647493772 0.4835855560598\n", 7948 " 333.333 22.98314371029 0.4542918950801\n", 7949 " 400 22.80339361568 0.4497107885587\n", 7950 " 466.667 22.91634335366 0.4525833037874\n", 7951 " 533.333 22.59774140046 0.4445334311324\n", 7952 " 666.667 20.9177750759 0.4046955726046\n", 7953 " 833.333 20.71792550566 0.4002363835007\n", 7954 " 1000 19.54080006349 0.3751112751853\n", 7955 ] 7956 7957 # Check data_set_600 7958 file = open(files[0][0]+sep+files[0][1]) 7959 lines = file.readlines() 7960 file.close() 7961 self.assertEqual(len(data_set_600), len(lines)) 7962 for i in range(len(data_set_600)): 7963 # Make the string test 7964 self.assertEqual(data_set_600[i], lines[i]) 7965 7966 # Define how files should look like 7967 data_set_500 = [ 7968 "50.6846152368\n", 7969 "0.04\n", 7970 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 7971 "# G10\n", 7972 " 50 22.28084307393 0.2944966344183\n", 7973 " 100 21.93494977761 0.2910362768307\n", 7974 " 150 21.09850032232 0.282892238351\n", 7975 " 200 20.86493960397 0.2806737853646\n", 7976 " 250 20.75287269752 0.2796178205016\n", 7977 " 300 20.25597152406 0.2750013546989\n", 7978 " 350 19.92172163467 0.2719555756504\n", 7979 " 400 19.97712052922 0.272457105051\n", 7980 " 450 19.46807010415 0.2678972122793\n", 7981 " 500 19.76875460947 0.2705774849203\n", 7982 " 550 19.39161367402 0.2672216964327\n", 7983 " 600 19.03949517697 0.2641417899694\n", 7984 " 650 19.12218812132 0.2648605059901\n", 7985 " 700 19.01037461457 0.2638893584683\n", 7986 " 800 18.83395162904 0.2623674321143\n", 7987 " 900 18.47529972436 0.2593123604687\n", 7988 " 1000 18.5252023121 0.2597343394038\n", 7989 "# D11\n", 7990 " 50 22.15403890237 0.3285588379827\n", 7991 " 100 21.80946781746 0.3247185598713\n", 7992 " 150 21.77715415505 0.324361526682\n", 7993 " 200 21.41647464235 0.3204122024881\n", 7994 " 250 21.17099940822 0.3177616325958\n", 7995 " 300 21.03740030577 0.3163316496664\n", 7996 " 350 20.95393648281 0.3154427665172\n", 7997 " 400 20.93311399332 0.315221543436\n", 7998 " 450 20.18219905222 0.3073848655291\n", 7999 " 500 19.93599065085 0.3048744697057\n", 8000 " 550 19.68475725452 0.3023424499113\n", 8001 " 600 19.33575433934 0.2988741928798\n", 8002 " 650 19.53915692194 0.3008886196853\n", 8003 " 700 19.2018754351 0.2975587767134\n", 8004 " 800 18.82360965368 0.2938866923878\n", 8005 " 900 18.71861761238 0.2928790380131\n", 8006 " 1000 17.95878049287 0.2857341721151\n", 8007 ] 8008 8009 # Check data_set_500 8010 file = open(files[1][0]+sep+files[1][1]) 8011 lines = file.readlines() 8012 file.close() 8013 self.assertEqual(len(data_set_500), len(lines)) 8014 for i in range(len(data_set_500)): 8015 # Make the string test 8016 self.assertEqual(data_set_500[i], lines[i]) 8017 8018 # Test local dir tests. This will be turned off in system test. 8019 turn_on_local_dir_test = False 8020 8021 if turn_on_local_dir_test: 8022 ## Now check to local folder with None argument. 8023 # Write input 8024 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None) 8025 8026 # Check the r2eff set files. 8027 print("\nChecking the R2eff input set files.") 8028 files = [[path.join(getcwd(), 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), 'cluster1'), 'sherekhan_frq2.in']] 8029 8030 # First check file exists 8031 for dir, file in files: 8032 print(dir+sep+file) 8033 self.assert_(access(dir+sep+file, F_OK)) 8034 8035 ## Now check to local folder with dir argument. 8036 # Write input 8037 set_dir = "Test_ShereKhan" 8038 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=set_dir) 8039 8040 # Check the r2eff set files. 8041 print("\nChecking the R2eff input set files.") 8042 files = [[path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq2.in']] 8043 8044 # First check file exists 8045 for dir, file in files: 8046 print(dir+sep+file) 8047 self.assert_(access(dir+sep+file, F_OK))
8048 8049
8050 - def test_sprangers_data_to_mmq_cr72(self, model=None):
8051 """Test the 'MMQ CR72' model fitting against Remco Sprangers' ClpP data. 8052 8053 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MMQ CPMG data with a fixed relaxation time period. 8054 """ 8055 8056 # Reset. 8057 self.interpreter.reset() 8058 8059 # Create the data pipe and load the base data. 8060 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 8061 self.interpreter.state.load(data_path+sep+'r2eff_values') 8062 8063 # The model data pipe. 8064 model = 'MMQ CR72' 8065 pipe_name = "%s - relax_disp" % model 8066 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 8067 self.interpreter.pipe.switch(pipe_name=pipe_name) 8068 8069 # Set the model. 8070 self.interpreter.relax_disp.select_model(model=model) 8071 8072 # Cluster everything. 8073 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 8074 8075 # Copy the data. 8076 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 8077 8078 # Alias the spins. 8079 spin135S = cdp.mol[0].res[0].spin[0] 8080 spin135F = cdp.mol[0].res[0].spin[1] 8081 spin137S = cdp.mol[0].res[1].spin[0] 8082 spin137F = cdp.mol[0].res[1].spin[1] 8083 8084 # The R20 keys. 8085 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 8086 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8087 8088 # Set the cluster specific parameters (only for the first spin). 8089 spin135S.pA = 0.836591763632 8090 spin135S.kex = 241.806525261 8091 8092 # Set the initial parameter values. 8093 spin135S.r2 = {r20_key1: 28.2493431552, r20_key2: 31.7517334715} 8094 spin135S.dw = 0.583003118785 8095 spin135S.dwH = 0.0361441944301 8096 8097 spin135F.r2 = {r20_key1: 42.7201839991, r20_key2: 57.3178617389} 8098 spin135F.dw = 0.805849745104 8099 spin135F.dwH = 0.0215791945715 8100 8101 spin137S.r2 = {r20_key1: 26.0134115256, r20_key2: 30.575806934} 8102 spin137S.dw = 0.688107568372 8103 spin137S.dwH = 0.0344463604043 8104 8105 spin137F.r2 = {r20_key1: 46.6969397337, r20_key2: 58.602384101} 8106 spin137F.dw = 0.94978299907 8107 spin137F.dwH = 1.4818877939e-07 8108 8109 # Low precision optimisation. 8110 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-10, max_iter=1000) 8111 8112 # Printout. 8113 print("\n\nOptimised parameters:\n") 8114 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 8115 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1])) 8116 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2])) 8117 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 8118 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 8119 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 8120 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 8121 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 8122 print("\n # Set the cluster specific parameters (only for the first spin).") 8123 print(" spin135S.pA = %s" % spin135S.pA) 8124 print(" spin135S.kex = %s" % spin135S.kex) 8125 print("\n # Set the initial parameter values.") 8126 print(" spin135S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135S.r2[r20_key1], spin135S.r2[r20_key2])) 8127 print(" spin135S.dw = %s" % spin135S.dw) 8128 print(" spin135S.dwH = %s" % spin135S.dwH) 8129 print("\n spin135F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135F.r2[r20_key1], spin135F.r2[r20_key2])) 8130 print(" spin135F.dw = %s" % spin135F.dw) 8131 print(" spin135F.dwH = %s" % spin135F.dwH) 8132 print("\n spin137S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137S.r2[r20_key1], spin137S.r2[r20_key2])) 8133 print(" spin137S.dw = %s" % spin137S.dw) 8134 print(" spin137S.dwH = %s" % spin137S.dwH) 8135 print("\n spin137F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137F.r2[r20_key1], spin137F.r2[r20_key2])) 8136 print(" spin137F.dw = %s" % spin137F.dw) 8137 print(" spin137F.dwH = %s" % spin137F.dwH) 8138 8139 # Checks for residue :135S. 8140 self.assertAlmostEqual(spin135S.r2[r20_key1], 28.2493445347425, 4) 8141 self.assertAlmostEqual(spin135S.r2[r20_key2], 31.7517352342937, 4) 8142 self.assertAlmostEqual(spin135S.pA, 0.836591714049569, 4) 8143 self.assertAlmostEqual(spin135S.dw, 0.583003004605869, 4) 8144 self.assertAlmostEqual(spin135S.dwH, 0.0361441894065963, 4) 8145 self.assertAlmostEqual(spin135S.kex/100, 241.806464344233/100, 4) 8146 self.assertAlmostEqual(spin135S.chi2, 12.4224060116473, 4) 8147 8148 # Checks for residue :135F. 8149 self.assertAlmostEqual(spin135F.r2[r20_key1], 42.7201844426839, 4) 8150 self.assertAlmostEqual(spin135F.r2[r20_key2], 57.3178718548898, 4) 8151 self.assertAlmostEqual(spin135F.pA, 0.836591714049569, 4) 8152 self.assertAlmostEqual(spin135F.dw, 0.805849748711916, 4) 8153 self.assertAlmostEqual(spin135F.dwH, 0.0215791669142752, 4) 8154 self.assertAlmostEqual(spin135F.kex/100, 241.806464344233/100, 4) 8155 self.assertAlmostEqual(spin135F.chi2, 12.4224060116473, 4) 8156 8157 # Checks for residue :137S. 8158 self.assertAlmostEqual(spin137S.r2[r20_key1], 26.013412509919, 4) 8159 self.assertAlmostEqual(spin137S.r2[r20_key2], 30.5758092335097, 4) 8160 self.assertAlmostEqual(spin137S.pA, 0.836591714049569, 4) 8161 self.assertAlmostEqual(spin137S.dw, 0.688107406812537, 4) 8162 self.assertAlmostEqual(spin137S.dwH, 0.034446357344577, 4) 8163 self.assertAlmostEqual(spin137S.kex/100, 241.806464344233/100, 4) 8164 self.assertAlmostEqual(spin137S.chi2, 12.4224060116473, 4) 8165 8166 # Checks for residue :137F. 8167 self.assertAlmostEqual(spin137F.r2[r20_key1], 46.696935090697, 4) 8168 self.assertAlmostEqual(spin137F.r2[r20_key2], 58.6023842513446, 4) 8169 self.assertAlmostEqual(spin137F.pA, 0.836591714049569, 4) 8170 self.assertAlmostEqual(spin137F.dw, 0.94978325541294, 4) 8171 self.assertAlmostEqual(spin137F.dwH, 1.5189362257653e-07, 4) 8172 self.assertAlmostEqual(spin137F.kex/100, 241.806464344233/100, 4) 8173 self.assertAlmostEqual(spin137F.chi2, 12.4224060116473, 4)
8174 8175
8176 - def test_sprangers_data_to_ns_mmq_2site(self, model=None):
8177 """Test the 'NS MMQ 2-site' model fitting against Remco Sprangers' ClpP data. 8178 8179 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MQ CPMG data with a fixed relaxation time period. 8180 """ 8181 8182 # Reset. 8183 self.interpreter.reset() 8184 8185 # Create the data pipe and load the base data. 8186 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 8187 self.interpreter.state.load(data_path+sep+'r2eff_values') 8188 8189 # The model data pipe. 8190 model = 'NS MMQ 2-site' 8191 pipe_name = "%s - relax_disp" % model 8192 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 8193 self.interpreter.pipe.switch(pipe_name=pipe_name) 8194 8195 # Set the model. 8196 self.interpreter.relax_disp.select_model(model=model) 8197 8198 # Cluster everything. 8199 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 8200 8201 # Copy the data. 8202 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 8203 8204 # Alias the spins. 8205 spin135S = cdp.mol[0].res[0].spin[0] 8206 spin135F = cdp.mol[0].res[0].spin[1] 8207 spin137S = cdp.mol[0].res[1].spin[0] 8208 spin137F = cdp.mol[0].res[1].spin[1] 8209 8210 # The R20 keys. 8211 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8212 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8213 8214 # Set the cluster specific parameters (only for the first spin). 8215 spin135S.pA = 0.847378444499757 8216 spin135S.kex = 264.055604934724329 8217 8218 # Set the initial parameter values. 8219 spin135S.r2 = {r20_key1: 30.315119723745390, r20_key2: 37.411874745645299} 8220 spin135S.dw = 0.585574008745351 8221 spin135S.dwH = 0.000000000000002 8222 8223 spin135F.r2 = {r20_key1: 41.440843383778287, r20_key2: 56.989726795397893} 8224 spin135F.dw = 0.856699277665748 8225 spin135F.dwH = 0.000000000582587 8226 8227 spin137S.r2 = {r20_key1: 23.051695938570266, r20_key2: 28.352806483953824} 8228 spin137S.dw = 0.772904450844973 8229 spin137S.dwH = 0.183351478512970 8230 8231 spin137F.r2 = {r20_key1: 44.702032074210429, r20_key2: 56.453146052685319} 8232 spin137F.dw = 0.984568590342831 8233 spin137F.dwH = 0.000000001993458 8234 8235 # Low precision optimisation. 8236 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-5, grad_tol=None, max_iter=100, constraints=True, scaling=True, verbosity=1) 8237 8238 # Printout. 8239 print("\n\nOptimised parameters:\n") 8240 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 8241 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1])) 8242 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2])) 8243 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 8244 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 8245 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 8246 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 8247 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 8248 8249 # FIXME: Remove this temporary return and properly check the results. 8250 return 8251 8252 # Checks for residue :135S. 8253 self.assertAlmostEqual(spin135S.r2[r20_key1], 30.3151197237454, 4) 8254 self.assertAlmostEqual(spin135S.r2[r20_key2], 37.4118747456453, 4) 8255 self.assertAlmostEqual(spin135S.pA, 0.847378444499757, 4) 8256 self.assertAlmostEqual(spin135S.dw, 0.585574008745351, 4) 8257 self.assertAlmostEqual(spin135S.dwH, 2e-15, 4) 8258 self.assertAlmostEqual(spin135S.kex, 264.055604934724, 4) 8259 self.assertAlmostEqual(spin135S.chi2, 13.859423588071, 1) 8260 8261 # Checks for residue :135F. 8262 self.assertAlmostEqual(spin135F.r2[r20_key1], 41.4408433837783, 4) 8263 self.assertAlmostEqual(spin135F.r2[r20_key2], 56.9897267953979, 4) 8264 self.assertAlmostEqual(spin135F.pA, 0.847378444499757, 4) 8265 self.assertAlmostEqual(spin135F.dw, 0.856699277665748, 4) 8266 self.assertAlmostEqual(spin135F.dwH, 5.82587e-10, 4) 8267 self.assertAlmostEqual(spin135F.kex, 264.055604934724, 4) 8268 self.assertAlmostEqual(spin135F.chi2, 13.859423588071, 1) 8269 8270 # Checks for residue :137S. 8271 self.assertAlmostEqual(spin137S.r2[r20_key1], 23.0516959385703, 4) 8272 self.assertAlmostEqual(spin137S.r2[r20_key2], 28.3528064839538, 4) 8273 self.assertAlmostEqual(spin137S.pA, 0.847378444499757, 4) 8274 self.assertAlmostEqual(spin137S.dw, 0.772904450844973, 4) 8275 self.assertAlmostEqual(spin137S.dwH, 0.18335147851297, 4) 8276 self.assertAlmostEqual(spin137S.kex, 264.055604934724, 4) 8277 self.assertAlmostEqual(spin137S.chi2, 13.859423588071, 1) 8278 8279 # Checks for residue :137F. 8280 self.assertAlmostEqual(spin137F.r2[r20_key1], 44.7020320742104, 4) 8281 self.assertAlmostEqual(spin137F.r2[r20_key2], 56.4531460526853, 4) 8282 self.assertAlmostEqual(spin137F.pA, 0.847378444499757, 4) 8283 self.assertAlmostEqual(spin137F.dw, 0.984568590342831, 4) 8284 self.assertAlmostEqual(spin137F.dwH, 2.0931309e-09, 4) 8285 self.assertAlmostEqual(spin137F.kex, 264.055604934724, 4) 8286 self.assertAlmostEqual(spin137F.chi2, 13.859423588071, 1)
8287 8288
8289 - def test_tp02_data_to_ns_r1rho_2site(self, model=None):
8290 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 8291 8292 # Setup the data. 8293 self.setup_tp02_data_to_ns_r1rho_2site() 8294 8295 # Alias the spins. 8296 spin1 = cdp.mol[0].res[0].spin[0] 8297 spin2 = cdp.mol[0].res[1].spin[0] 8298 8299 # The R20 keys. 8300 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8301 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8302 8303 # Checks for residue :1. 8304 self.assertAlmostEqual(spin1.r2[r20_key1], 8.50207717367548, 4) 8305 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4680429589972, 4) 8306 self.assertAlmostEqual(spin1.pA, 0.864523128842393, 4) 8307 self.assertAlmostEqual(spin1.dw, 8.85204828994151, 4) 8308 self.assertAlmostEqual(spin1.kex/1000, 1199.56359549637/1000, 4) 8309 self.assertAlmostEqual(spin1.chi2, 2.99182130153514, 4) 8310 8311 # Checks for residue :2. 8312 self.assertAlmostEqual(spin2.r2[r20_key1], 10.2099357790203, 4) 8313 self.assertAlmostEqual(spin2.r2[r20_key2], 16.2137648697873, 4) 8314 self.assertAlmostEqual(spin2.pA, 0.836488681031685, 4) 8315 self.assertAlmostEqual(spin2.dw, 9.5505714779503, 4) 8316 self.assertAlmostEqual(spin2.kex/1000, 1454.45726998929/1000, 4) 8317 self.assertAlmostEqual(spin2.chi2, 0.000402231563481261, 4)
8318 8319
8320 - def test_tp02_data_to_ns_r1rho_2site_cluster(self, model=None):
8321 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data, when performing clustering.""" 8322 8323 # Setup the data. 8324 self.setup_tp02_data_to_ns_r1rho_2site(clustering=True) 8325 8326 # Alias the spins. 8327 spin1 = cdp.mol[0].res[0].spin[0] 8328 spin2 = cdp.mol[0].res[1].spin[0] 8329 8330 # The R20 keys. 8331 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8332 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8333 8334 # Checks for residue :1. 8335 self.assertAlmostEqual(spin1.r2[r20_key1], 8.48607207881462, 4) 8336 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4527609061722, 4) 8337 self.assertAlmostEqual(spin1.pA, 0.863093838784425, 4) 8338 self.assertAlmostEqual(spin1.dw, 8.86218096536618, 4) 8339 self.assertAlmostEqual(spin1.kex/1000, 1186.22749648299/1000, 4) 8340 self.assertAlmostEqual(spin1.chi2, 3.09500996065247, 4) 8341 8342 # Checks for residue :2. 8343 self.assertAlmostEqual(spin2.r2[r20_key1], 10.4577906018883, 4) 8344 self.assertAlmostEqual(spin2.r2[r20_key2], 16.4455550953792, 4) 8345 self.assertAlmostEqual(spin2.pA, 0.863093838784425, 4) 8346 self.assertAlmostEqual(spin2.dw, 11.5841168862587, 4) 8347 self.assertAlmostEqual(spin2.kex/1000, 1186.22749648299/1000, 4) 8348 self.assertAlmostEqual(spin2.chi2, 3.09500996065247, 4)
8349 8350
8351 - def test_tp02_data_to_mp05(self):
8352 """Test the dispersion 'MP05' model fitting against the 'TP02' test data.""" 8353 8354 # Fixed time variable and the models. 8355 ds.fixed = True 8356 ds.models = ['R2eff', 'MP05'] 8357 8358 # Execute the script. 8359 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8360 8361 # Switch back to the data pipe for the optimisation. 8362 self.interpreter.pipe.switch('MP05 - relax_disp') 8363 8364 # The equivalent MP05 parameters. 8365 r1rho_prime = [[10.0058086343329, 15.005806870124], [12.0766320470785, 18.0767503536277]] 8366 pA = [0.775055484521586, 0.500000000036595] 8367 kex = [1235.20361276079, 2378.31403454691] 8368 delta_omega = [7.08194146569694, 5.4083562844306] 8369 chi2 = [0.0370400968727768, 0.182141732163934] 8370 8371 # Alias the spins. 8372 spin1 = cdp.mol[0].res[0].spin[0] 8373 spin2 = cdp.mol[0].res[1].spin[0] 8374 8375 # The R20 keys. 8376 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8377 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8378 8379 # Printout. 8380 print("\n\nOptimised parameters:\n") 8381 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 8382 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 8383 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 8384 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 8385 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 8386 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 8387 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 8388 8389 # Check each spin. 8390 spin_index = 0 8391 for spin, spin_id in spin_loop(return_id=True): 8392 # Printout. 8393 print("\nSpin %s." % spin_id) 8394 8395 # Check the fitted parameters. 8396 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8397 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8398 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 8399 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8400 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 8401 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 8402 8403 # Increment the spin index. 8404 spin_index += 1
8405 8406
8407 - def test_tp02_data_to_tap03(self):
8408 """Test the dispersion 'TAP03' model fitting against the 'TP02' test data.""" 8409 8410 # Fixed time variable and the models. 8411 ds.fixed = True 8412 ds.models = ['R2eff', 'TAP03'] 8413 8414 # Execute the script. 8415 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8416 8417 # Switch back to the data pipe for the optimisation. 8418 self.interpreter.pipe.switch('TAP03 - relax_disp') 8419 8420 # The equivalent TAP03 parameters. 8421 r1rho_prime = [[10.0058156589442, 15.005818505006], [12.0766046472748, 18.076648462452]] 8422 pA = [0.775042569092891, 0.500000000229685] 8423 kex = [1235.20852748765, 2379.47085580169] 8424 delta_omega = [7.08176806468445, 5.40708372863538] 8425 chi2 = [0.0371366837083293, 0.182212857256044] 8426 8427 # Alias the spins. 8428 spin1 = cdp.mol[0].res[0].spin[0] 8429 spin2 = cdp.mol[0].res[1].spin[0] 8430 8431 # The R20 keys. 8432 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8433 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8434 8435 # Printout. 8436 print("\n\nOptimised parameters:\n") 8437 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 8438 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 8439 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 8440 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 8441 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 8442 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 8443 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 8444 8445 # Switch to the 'MP05' model data pipe, then check for each spin. 8446 self.interpreter.pipe.switch('TAP03 - relax_disp') 8447 spin_index = 0 8448 for spin, spin_id in spin_loop(return_id=True): 8449 # Printout. 8450 print("\nSpin %s." % spin_id) 8451 8452 # Check the fitted parameters. 8453 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8454 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8455 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 8456 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8457 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 8458 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 8459 8460 # Increment the spin index. 8461 spin_index += 1
8462 8463
8464 - def test_tp02_data_to_tp02(self):
8465 """Test the relaxation dispersion 'TP02' model curve fitting to fixed time synthetic data.""" 8466 8467 # Fixed time variable. 8468 ds.fixed = True 8469 8470 # Execute the script. 8471 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8472 8473 # The original parameters. 8474 r1rho_prime = [[10.0, 15.0], [12.0, 18.0]] 8475 pA = 0.7654321 8476 kex = 1234.56789 8477 delta_omega = [7.0, 9.0] 8478 8479 # The R20 keys. 8480 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8481 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8482 8483 # Switch to the 'TP02' model data pipe, then check for each spin. 8484 self.interpreter.pipe.switch('TP02 - relax_disp') 8485 spin_index = 0 8486 for spin, spin_id in spin_loop(return_id=True): 8487 # Printout. 8488 print("\nSpin %s." % spin_id) 8489 8490 # Check the fitted parameters. 8491 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8492 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8493 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8494 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 3) 8495 8496 # Increment the spin index. 8497 spin_index += 1
8498 8499
8501 """System test of the value.write function to write intensities for an R1rho setup. 8502 This system test is to make sure, that modifying the API for special parameters theta and w_eff does not alter the functionality value.write. 8503 8504 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8505 """ 8506 8507 # Load the state. 8508 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8509 self.interpreter.state.load(statefile, force=True) 8510 8511 # Set filepaths. 8512 int_filepath = ds.tmpdir+sep+'int.out' 8513 8514 # Write out the intensity parameter file. 8515 # The writing out of intensity file is to make sure the API function retains its function after modification for special parameters. 8516 self.interpreter.value.write(param='peak_intensity', file='int.out', dir=ds.tmpdir, scaling=1.0, force=True) 8517 8518 # Test the file exists. 8519 self.assert_(access(int_filepath, F_OK)) 8520 8521 # Open the files for testing. 8522 int_file = open(int_filepath, 'r') 8523 8524 # Loop over the intensity file to test values. 8525 for line in int_file: 8526 # Skip lines starting with #. 8527 if line[0] == "#": 8528 continue 8529 8530 # Split the line 8531 linesplit = line.split() 8532 8533 # Assume values 8534 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8535 self.assertEqual(linesplit[5], "115571.4") 8536 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8537 self.assertEqual(linesplit[5], "68377.52") 8538 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8539 self.assertEqual(linesplit[5], "9141.689") 8540 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8541 self.assertEqual(linesplit[5], "29123.77") 8542 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8543 self.assertEqual(linesplit[5], "58914.94") 8544 8545 # Close files 8546 int_file.close()
8547 8548
8550 """System test of the value.write function to write return values of theta from calc_rotating_frame_params() function for an R1rho setup. 8551 8552 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8553 """ 8554 8555 # Load the state. 8556 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8557 self.interpreter.state.load(statefile, force=True) 8558 8559 # Set filepaths. 8560 theta_filepath = ds.tmpdir+sep+'theta.out' 8561 8562 # Write out the theta parameter file. 8563 self.interpreter.value.write(param='theta', file='theta.out', dir=ds.tmpdir, scaling=1.0, force=True) 8564 8565 # Test the file exists. 8566 self.assert_(access(theta_filepath, F_OK)) 8567 8568 # Open the files for testing. 8569 theta_file = open(theta_filepath, 'r') 8570 8571 # Loop over the theta file to test values. 8572 for line in theta_file: 8573 # Skip lines starting with #. 8574 if line[0] == "#": 8575 continue 8576 # Print lines, not including newline character. 8577 print(line[:-1]) 8578 8579 # Split the line 8580 linesplit = line.split() 8581 8582 # Assume values 8583 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8584 self.assertNotEqual(linesplit[5], "None") 8585 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8586 self.assertNotEqual(linesplit[5], "None") 8587 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8588 self.assertNotEqual(linesplit[5], "None") 8589 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8590 self.assertNotEqual(linesplit[5], "None") 8591 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8592 self.assertNotEqual(linesplit[5], "None") 8593 8594 # Close files 8595 theta_file.close()
8596 8597
8599 """System test of the value.write function to write return values of w_eff from calc_rotating_frame_params() function for an R1rho setup. 8600 8601 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8602 """ 8603 8604 # Load the state. 8605 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8606 self.interpreter.state.load(statefile, force=True) 8607 8608 # Set filepaths. 8609 w_eff_filepath = ds.tmpdir+sep+'w_eff.out' 8610 8611 # Write out the w_eff parameter file. 8612 self.interpreter.value.write(param='w_eff', file='w_eff.out', dir=ds.tmpdir, scaling=1.0, force=True) 8613 8614 # Test the file exists. 8615 self.assert_(access(w_eff_filepath, F_OK)) 8616 8617 # Open the files for testing. 8618 w_eff_file = open(w_eff_filepath, 'r') 8619 8620 # Loop over the w_eff file to test values. 8621 for line in w_eff_file: 8622 # Skip lines starting with #. 8623 if line[0] == "#": 8624 continue 8625 # Print lines, not including newline character. 8626 print(line[:-1]) 8627 8628 # Split the line 8629 linesplit = line.split() 8630 8631 # Assume values 8632 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8633 self.assertNotEqual(linesplit[5], "None") 8634 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8635 self.assertNotEqual(linesplit[5], "None") 8636 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8637 self.assertNotEqual(linesplit[5], "None") 8638 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8639 self.assertNotEqual(linesplit[5], "None") 8640 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8641 self.assertNotEqual(linesplit[5], "None") 8642 8643 # Close files 8644 w_eff_file.close()
8645 8646
8648 """System test of the auto_analysis value.write function to write theta and w_eff values for an R1rho setup. 8649 8650 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8651 """ 8652 8653 # Load the state. 8654 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344.bz2' 8655 self.interpreter.state.load(statefile, force=True) 8656 8657 # Set pipe name, bundle and type. 8658 pipe_name = 'base pipe' 8659 pipe_bundle = 'relax_disp' 8660 pipe_type = 'relax_disp' 8661 8662 # The path to the data files. 8663 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 8664 8665 # Deselect all spins 8666 self.interpreter.deselect.all() 8667 8668 # Specify spins to be selected. 8669 select_spin_ids = [ 8670 ":13@N", 8671 ":15@N", 8672 ":16@N", 8673 ":25@N", 8674 ":26@N", 8675 ":28@N", 8676 ":39@N", 8677 ":40@N", 8678 ":41@N", 8679 ":43@N", 8680 ":44@N", 8681 ":45@N", 8682 ":49@N", 8683 ":52@N", 8684 ":53@N"] 8685 8686 # Reverse the selection for the spins. 8687 for curspin in select_spin_ids: 8688 print("Selecting spin %s"%curspin) 8689 self.interpreter.deselect.reverse(spin_id=curspin) 8690 8691 # Read the R1 data 8692 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 8693 8694 # The dispersion models. 8695 MODELS = ['R2eff'] 8696 8697 # The grid search size (the number of increments per dimension). 8698 GRID_INC = 4 8699 8700 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 8701 MC_NUM = 3 8702 8703 # Model selection technique. 8704 MODSEL = 'AIC' 8705 8706 # Execute the auto-analysis (fast). 8707 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 8708 OPT_FUNC_TOL = 1e-1 8709 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 8710 OPT_MAX_ITERATIONS = 1000 8711 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 8712 8713 # Run the analysis. 8714 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=ds.tmpdir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 8715 8716 ## Check for file creation 8717 # Set filepaths. 8718 theta_filepath = ds.tmpdir+sep+MODELS[0]+sep+'theta.out' 8719 w_eff_filepath = ds.tmpdir+sep+MODELS[0]+sep+'w_eff.out' 8720 8721 # Test the files exists. 8722 self.assert_(access(theta_filepath, F_OK)) 8723 self.assert_(access(w_eff_filepath, F_OK)) 8724 8725 # Open the files for testing. 8726 theta_file = open(theta_filepath, 'r') 8727 theta_result = [ 8728 "# Parameter description: Rotating frame tilt angle : ( theta = arctan(w_1 / Omega) ) (rad).\n", 8729 "#\n", 8730 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n", 8731 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8732 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8733 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8734 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8735 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8736 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8737 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8738 "None 13 L None N 1.83827367612531 None 1.79015307643158 None 2.2768687598681 None 2.08461171779445 None 2.00120623474388 None 1.92825070277699 None 1.47212860033516 None 1.12978017906854 None 1.20415336139956 None 0.901691390796334 None 0.687390207543568 None 0.455635480573046 None 0.281637123971289 None 0.138259661766539 None \n", 8739 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8740 "None 15 R None N 1.58367544790673 None 1.58127411936947 None 1.61085209029811 None 1.59731540507347 None 1.59237108385522 None 1.58834866344307 None 1.2251048782537 None 0.938142786712004 None 1.03297495592991 None 0.683284686224254 None 0.594447788256641 None 0.383528609383686 None 0.262780814059893 None 0.133469839450564 None \n", 8741 "None 16 T None N 1.40984232256624 None 1.43947245672073 None 1.10299856647417 None 1.24811470332083 None 1.30521602599932 None 1.35302443831853 None 1.07923777467974 None 0.833345927788896 None 0.934350308974616 None 0.581325254389991 None 0.543659670184793 None 0.346238480454282 None 0.251454336191817 None 0.130436714663781 None \n", 8742 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8743 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8744 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8745 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8746 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8747 "None 25 Q None N 1.81569700258844 None 1.77137827615015 None 2.23175875585624 None 2.04612705363098 None 1.9673155780155 None 1.89908711012298 None 1.44829660124856 None 1.11023386429581 None 1.18716091371256 None 0.877306975624962 None 0.677790118853413 None 0.447932002242236 None 0.279785379050945 None 0.137802891887767 None \n", 8748 "None 26 Q None N 1.61128821168674 None 1.60374392042003 None 1.69619923953765 None 1.65403989292986 None 1.63856717205868 None 1.62595755714564 None 1.24977859227795 None 0.956353494917591 None 1.04972090035774 None 0.702164059520172 None 0.603227813742091 None 0.390116910781037 None 0.264658552037535 None 0.133960994297096 None \n", 8749 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8750 "None 28 Q None N 1.65182797011356 None 1.63676707684161 None 1.81830827892972 None 1.7365089711986 None 1.70601955220877 None 1.68102938663686 None 1.28685736157369 None 0.984047498595701 None 1.0749792109454 None 0.731585685663053 None 0.616577997665602 None 0.400219205533665 None 0.267471993812649 None 0.134690869499646 None \n", 8751 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8752 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8753 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8754 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8755 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8756 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8757 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8758 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8759 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8760 "None 39 L None N 1.76426439181176 None 1.72885318885161 None 2.11826300085737 None 1.95430201082222 None 1.88794717058464 None 1.83172922971397 None 1.39549951193417 None 1.06783946148624 None 1.14997013232702 None 0.826128785942585 None 0.657105386950171 None 0.431542911580536 None 0.275725736430539 None 0.136791385554619 None \n", 8761 "None 40 M None N 1.5521741199158 None 1.55564594516135 None 1.51290906497298 None 1.53245929150759 None 1.53960430408466 None 1.54541832596591 None 1.19750223001929 None 0.917959090226757 None 1.01428385962747 None 0.662779584695967 None 0.584708929219264 None 0.376271266885303 None 0.260671619214194 None 0.132914250767089 None \n", 8762 "None 41 A None N 1.68339451828261 None 1.66252964414082 None 1.90911961276946 None 1.79959323497326 None 1.75801925517113 None 1.72370710837265 None 1.31646868936419 None 1.00647189763597 None 1.09525348649914 None 0.75605702767542 None 0.627395557358039 None 0.408481831044309 None 0.269716174238842 None 0.135267948387412 None \n", 8763 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8764 "None 43 F None N 1.58506597154432 None 1.58240542750303 None 1.61517196062351 None 1.60017740004898 None 1.59469990835425 None 1.59024353162528 None 1.22633651794829 None 0.939047922181951 None 1.03380990731605 None 0.684214484755514 None 0.594884298549546 None 0.383855128702894 None 0.262874695048502 None 0.13349447283116 None \n", 8765 "None 44 I None N 1.57575471961837 None 1.57483015671791 None 1.58622388390755 None 1.58100758841935 None 1.57910319967536 None 1.57755415552211 None 1.21811077066835 None 0.933010299763027 None 1.02823520295828 None 0.67802911457195 None 0.591972285081647 None 0.381678892926696 None 0.262247347241724 None 0.133329708422379 None \n", 8766 "None 45 K None N 1.77147501495754 None 1.73479633022489 None 2.13509660780385 None 1.96751045408372 None 1.89924480319914 None 1.84124387452692 None 1.40277881643715 None 1.07361367582571 None 1.15506365550891 None 0.832963505534767 None 0.659913187081268 None 0.433751178249555 None 0.276282572106685 None 0.13693095791902 None \n", 8767 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8768 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8769 "None 49 A None N 2.00297059962685 None 1.92978318052058 None 2.53305709323468 None 2.33052197276846 None 2.22870514722639 None 2.13201782446864 None 1.6587904412969 None 1.29333162369472 None 1.34311052758116 None 1.12559033900783 None 0.770195063841652 None 0.524846264860003 None 0.296857751274362 None 0.141908833673671 None \n", 8770 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8771 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8772 "None 52 V None N 1.82421571143794 None 1.77845404105203 None 2.24910726268822 None 2.06078232916932 None 1.98017451806059 None 1.91012195713554 None 1.45724107606646 None 1.11753869321304 None 1.19352234944057 None 0.886361068343012 None 0.681372607920812 None 0.450799407357501 None 0.280478735779163 None 0.137974257665877 None \n", 8773 "None 53 A None N 2.05019708195234 None 1.97089957318506 None 2.58789168363698 None 2.39027806684801 None 2.28731354878582 None 2.1872118539319 None 1.7165709935896 None 1.34832362477229 None 1.38879751095815 None 1.2085314357749 None 0.799450059125864 None 0.550583841461621 None 0.30195492609136 None 0.143090604877102 None \n", 8774 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8775 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8776 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8777 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8778 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n" 8779 ] 8780 # Check the created theta file. 8781 lines = theta_file.readlines() 8782 for i in range(len(lines)): 8783 # Test lines starting with # 8784 if theta_result[i][0] == "#": 8785 self.assertEqual(theta_result[i], lines[i]) 8786 # If the line is equal each other, make a line comparison. This should catch lines with None values. 8787 if theta_result[i] == lines[i]: 8788 self.assertEqual(theta_result[i], lines[i]) 8789 # If the line is not equal each other, make a slower comparison of values. 8790 else: 8791 # Print lines if they don't match. To help find differences. 8792 print(theta_result[i]) 8793 print(lines[i]) 8794 8795 # First test first 62 characters containing spin information 8796 self.assertEqual(theta_result[i][:62], lines[i][:62]) 8797 8798 # Make a string split after 62 characters. Select each second element, so None values are skipped. 8799 theta_result_s = theta_result[i][62:].split()[::2] 8800 print(theta_result_s ) 8801 lines_s = lines[i][62:].split()[::2] 8802 print(lines_s) 8803 # Loop over the value elements 8804 for j in range(len(lines_s)): 8805 print(theta_result_s[j], lines_s[j]) 8806 # Assume a precision to digits. 8807 self.assertAlmostEqual(float(theta_result_s[j]), float(lines_s[j]), 14) 8808 8809 # Close file 8810 theta_file.close() 8811 8812 w_eff_file = open(w_eff_filepath, 'r') 8813 w_eff_result = [ 8814 "# Parameter description: Effective field in rotating frame : ( w_eff = sqrt(Omega^2 + w_1^2) ) (rad.s^-1).\n", 8815 "#\n", 8816 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n", 8817 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8818 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8819 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8820 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8821 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8822 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8823 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8824 "None 13 L None N 8737.12883908829 None 10612.1226552258 None 3558.93734069587 None 4698.27194621826 None 5534.46153956037 None 6599.82570817753 None 8467.62674839481 None 9318.00441649087 None 11095.2662520767 None 6412.33580591254 None 13279.9803044242 None 11430.254637056 None 30318.7268264644 None 61141.1080046448 None \n", 8825 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8826 "None 15 R None N 8427.14155005377 None 10358.3995676635 None 2710.22680763322 None 4093.04942975722 None 5030.86065069262 None 6183.60685459024 None 8956.28403254202 None 10448.6627754369 None 12060.4428066937 None 7966.64282975241 None 15045.8392092364 None 13441.3586252373 None 32438.4764809909 None 63321.5201471181 None \n", 8827 "None 16 T None N 8536.7818857229 None 10447.792678989 None 3034.01707453628 None 4314.2767521567 None 5212.43600885913 None 6332.21319855067 None 9558.14311447582 None 11384.2336494604 None 12879.4604966293 None 9159.34604475399 None 16290.1746838959 None 14821.0200530829 None 33866.5933527757 None 64785.3205696403 None \n", 8828 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8829 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8830 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8831 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8832 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8833 "None 25 Q None N 8685.60895531182 None 10569.7459677762 None 3430.51272680396 None 4601.75421490393 None 5452.76508815826 None 6531.46859076009 None 8490.06475886501 None 9406.58372902508 None 11169.7602637607 None 6540.38696356753 None 13437.7348017798 None 11613.1632549021 None 30514.0741594726 None 61342.4792156782 None \n", 8834 "None 26 Q None N 8433.35533683544 None 10363.4554631194 None 2729.48656005151 None 4105.82770792005 None 5041.26238350827 None 6192.07245313098 None 8880.08366342131 None 10312.6868786802 None 11942.8320576165 None 7787.44854491812 None 14853.4987024375 None 13225.7048162038 None 32213.6690023282 None 63090.7407990801 None \n", 8835 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8836 "None 28 Q None N 8454.18308422202 None 10380.4112885894 None 2793.17494362899 None 4148.43953208179 None 5076.02756135055 None 6220.40920270029 None 8777.91538040813 None 10118.8737706315 None 11775.8792998529 None 7528.90766101027 None 14572.4015102398 None 12909.211050939 None 31882.8171856889 None 62750.9120842199 None \n", 8837 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8838 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8839 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8840 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8841 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8842 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8843 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8844 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8845 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8846 "None 39 L None N 8586.6405431352 None 10488.5710521378 None 3171.59430904777 None 4412.11227722123 None 5293.69814015286 None 6399.27143075725 None 8557.58926327909 None 9617.45773774313 None 11347.9169998729 None 6840.20010813426 None 13795.1250622375 None 12024.9041436853 None 30951.651485352 None 61793.2130509111 None \n", 8847 "None 40 M None N 8427.90394711227 None 10359.0198301036 None 2712.59646573568 None 4094.61889210019 None 5032.13762965554 None 6184.6458240746 None 9049.68452800053 None 10607.7913029633 None 12198.5639821231 None 8174.23271685285 None 15266.4924700447 None 13687.9010998756 None 32694.9043143038 None 63584.6371927381 None \n", 8848 "None 41 A None N 8480.14299737436 None 10401.5648897003 None 2870.79081440785 None 4201.09083283266 None 5119.14733505123 None 6255.64579267482 None 8706.50768957471 None 9972.71017314947 None 11650.5225246067 None 7331.28858930568 None 14354.1616183112 None 12662.3378547029 None 31623.9195264738 None 62484.8290612112 None \n", 8849 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8850 "None 43 F None N 8427.30062786474 None 10358.5289868368 None 2710.7214015056 None 4093.37694357637 None 5031.12711571215 None 6183.82364721878 None 8952.31975962078 None 10441.7375680915 None 12054.4435931163 None 7957.55789315654 None 15036.1316712316 None 13430.4914212645 None 32427.1596037519 None 63309.9050677925 None \n", 8851 "None 44 I None N 8426.54623319716 None 10357.9152496503 None 2708.3751705368 None 4091.82359712664 None 5029.86337809029 None 6182.79552045043 None 8979.12144335458 None 10488.2688526334 None 12094.7720286018 None 8018.51779989075 None 15101.1843990883 None 13503.2816173444 None 32502.9389163062 None 63387.6763306952 None \n", 8852 "None 45 K None N 8599.01176345321 None 10498.7013581079 None 3204.93649737055 None 4436.14046641897 None 5313.74138343704 None 6415.86177652694 None 8546.79665373249 None 9587.16245449134 None 11322.2529042385 None 6797.53838612575 None 13745.1536613763 None 11967.5433300612 None 30890.8603419261 None 61730.6213936947 None \n", 8853 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8854 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8855 "None 49 A None N 9279.63849130869 None 11063.0654625247 None 4737.11992391463 None 5643.40583860235 None 6356.45614406507 None 7302.87406141381 None 8459.17105047661 None 8761.54554569995 None 10632.2343488142 None 5572.92782399155 None 12102.1714908775 None 10037.6988885228 None 28806.6916858172 None 59579.0348769179 None \n", 8856 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8857 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8858 "None 52 V None N 8704.45610117774 None 10585.2389163429 None 3477.9549539207 None 4637.22923167743 None 5482.73656118686 None 6556.5108895527 None 8481.06470969555 None 9372.86414918436 None 11141.3782476763 None 6491.79686536093 None 13378.2843939736 None 11544.3205736882 None 30440.62308788 None 61266.7742546508 None \n", 8859 "None 53 A None N 9497.02860450276 None 11246.0339326126 None 5149.96766581255 None 5994.15475647208 None 6669.81232845336 None 7577.19152075731 None 8516.77431951689 None 8639.36099840319 None 10531.7750336522 None 5378.79193153767 None 11752.8060152439 None 9613.59939949642 None 28334.9153747994 None 59090.2988815445 None \n", 8860 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8861 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8862 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8863 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8864 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n" 8865 ] 8866 # Check the created w_eff file. 8867 lines = w_eff_file.readlines() 8868 for i in range(len(lines)): 8869 # Test lines starting with # 8870 if w_eff_result[i][0] == "#": 8871 self.assertEqual(w_eff_result[i], lines[i]) 8872 # If the line is equal each other, make a line comparison. This should catch lines with None values. 8873 if w_eff_result[i] == lines[i]: 8874 self.assertEqual(w_eff_result[i], lines[i]) 8875 # If the line is not equal each other, make a slower comparison of values. 8876 else: 8877 # Print lines if they don't match. To help find differences. 8878 print(w_eff_result[i]) 8879 print(lines[i]) 8880 8881 # First test first 62 characters containing spin information 8882 self.assertEqual(w_eff_result[i][:62], lines[i][:62]) 8883 8884 # Make a string split after 62 characters. Select each second element, so None values are skipped. 8885 w_eff_result_s = w_eff_result[i][62:].split()[::2] 8886 print(w_eff_result_s ) 8887 lines_s = lines[i][62:].split()[::2] 8888 print(lines_s) 8889 # Loop over the value elements 8890 for j in range(len(lines_s)): 8891 print(w_eff_result_s[j], lines_s[j]) 8892 # Assume a precision to digits. 8893 self.assertAlmostEqual(float(w_eff_result_s[j]), float(lines_s[j]), 14) 8894 8895 # Close file 8896 w_eff_file.close()
8897 8898
8900 """Test the user function for estimating R2eff errors from exponential curve fitting, and compare it with Monte-Carlo simulations. 8901 8902 This follows Task 7822. 8903 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 8904 8905 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 8906 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 8907 """ 8908 8909 # Load the data. 8910 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 8911 8912 # Set pipe name, bundle and type. 8913 pipe_name = 'base pipe' 8914 pipe_bundle = 'relax_disp' 8915 pipe_type = 'relax_disp' 8916 8917 # Create the data pipe. 8918 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 8919 8920 file = data_path + '1_setup_r1rho_GUI.py' 8921 self.interpreter.script(file=file, dir=None) 8922 8923 # Deselect all spins. 8924 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 8925 8926 # Select one spin. 8927 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 8928 8929 # Set the model. 8930 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 8931 8932 # Check if intensity errors have already been calculated. 8933 check_intensity_errors() 8934 8935 # Do a grid search. 8936 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 8937 8938 # Set algorithm. 8939 min_algor = 'Newton' 8940 constraints = True 8941 if constraints: 8942 min_options = ('%s'%(min_algor),) 8943 #min_algor = 'Log barrier' 8944 min_algor = 'Method of Multipliers' 8945 scaling_matrix = assemble_scaling_matrix(scaling=True) 8946 8947 # Collect spins 8948 all_spin_ids = [] 8949 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8950 all_spin_ids.append(spin_id) 8951 8952 spins = spin_ids_to_containers(all_spin_ids[:1]) 8953 8954 # Get constraints 8955 A, b = linear_constraints(spins=spins, scaling_matrix=scaling_matrix[0]) 8956 else: 8957 min_options = () 8958 A, b = None, None 8959 min_options = () 8960 sim_boot = 200 8961 scaling_list = [1.0, 1.0] 8962 8963 # Minimise. 8964 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints, verbosity=1) 8965 8966 # Loop over old err attributes. 8967 err_attr_list = ['r2eff_err', 'i0_err'] 8968 8969 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8970 # Loop over old err attributes. 8971 for err_attr in err_attr_list: 8972 if hasattr(cur_spin, err_attr): 8973 delattr(cur_spin, err_attr) 8974 8975 # Collect the estimation data from boot. 8976 my_dic = {} 8977 param_key_list = [] 8978 est_keys = [] 8979 est_key = '-2' 8980 est_keys.append(est_key) 8981 spin_id_list = [] 8982 8983 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8984 # Add key to dic. 8985 my_dic[spin_id] = {} 8986 8987 # Add key for estimate. 8988 my_dic[spin_id][est_key] = {} 8989 8990 # Add spin key to list. 8991 spin_id_list.append(spin_id) 8992 8993 # Generate spin string. 8994 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 8995 8996 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 8997 # Generate the param_key. 8998 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 8999 9000 # Append key. 9001 param_key_list.append(param_key) 9002 9003 # Add key to dic. 9004 my_dic[spin_id][est_key][param_key] = {} 9005 9006 values = [] 9007 errors = [] 9008 times = [] 9009 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 9010 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 9011 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 9012 times.append(time) 9013 9014 # Convert to numpy array. 9015 values = asarray(values) 9016 errors = asarray(errors) 9017 times = asarray(times) 9018 9019 r2eff = getattr(cur_spin, 'r2eff')[param_key] 9020 i0 = getattr(cur_spin, 'i0')[param_key] 9021 9022 R_m_sim_l = [] 9023 I0_m_sim_l = [] 9024 for j in range(sim_boot): 9025 if j in range(0, 100000, 100): 9026 print("Simulation %i"%j) 9027 # Start minimisation. 9028 9029 # Produce errors 9030 I_err = [] 9031 for j, error in enumerate(errors): 9032 I_error = gauss(values[j], error) 9033 I_err.append(I_error) 9034 # Convert to numpy array. 9035 I_err = asarray(I_err) 9036 9037 x0 = [r2eff, i0] 9038 setup(num_params=len(x0), num_times=len(times), values=I_err, sd=errors, relax_times=times, scaling_matrix=scaling_list) 9039 9040 # Ref input. 9041 #def generic_minimise(func=None, dfunc=None, d2func=None, args=(), x0=None, min_algor=None, min_options=None, func_tol=1e-25, grad_tol=None, maxiter=1e6, A=None, b=None, l=None, u=None, c=None, dc=None, d2c=None, print_flag=0, print_prefix="", full_output=False): 9042 # l=l, u=u, c=c, dc=dc, d2c=d2c 9043 # l: Lower bound constraint vector (l <= x <= u). 9044 # u: Upper bound constraint vector (l <= x <= u). 9045 # c: User supplied constraint function. 9046 # dc: User supplied constraint gradient function. 9047 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=func, dfunc=dfunc, d2func=d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, A=A, b=b, full_output=True, print_flag=0) 9048 9049 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 9050 R_m_sim_l.append(R_m_sim_j) 9051 I0_m_sim_l.append(I0_m_sim_j) 9052 9053 # Get stats on distribution. 9054 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 9055 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 9056 my_dic[spin_id][est_key][param_key]['r2eff_err'] = sigma_R_sim 9057 my_dic[spin_id][est_key][param_key]['i0_err'] = sigma_I0_sim 9058 9059 # Estimate R2eff errors. 9060 self.interpreter.relax_disp.r2eff_err_estimate() 9061 9062 est_key = '-1' 9063 est_keys.append(est_key) 9064 9065 # Collect data. 9066 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9067 # Add key for estimate. 9068 my_dic[spin_id][est_key] = {} 9069 9070 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9071 # Generate the param_key. 9072 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9073 9074 # Add key to dic. 9075 my_dic[spin_id][est_key][param_key] = {} 9076 9077 # Get the value. 9078 # Loop over err attributes. 9079 for err_attr in err_attr_list: 9080 if hasattr(cur_spin, err_attr): 9081 get_err_attr = getattr(cur_spin, err_attr)[param_key] 9082 else: 9083 get_err_attr = 0.0 9084 9085 # Save to dic. 9086 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 9087 9088 9089 # Make Carlo Simulations number 9090 mc_number_list = list(range(0, 1000, 250)) 9091 9092 sim_attr_list = ['chi2_sim', 'f_count_sim', 'g_count_sim', 'h_count_sim', 'i0_sim', 'iter_sim', 'peak_intensity_sim', 'r2eff_sim', 'select_sim', 'warning_sim'] 9093 9094 # Loop over the Monte Carlo simulations: 9095 for number in mc_number_list: 9096 # First delete old simulations. 9097 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9098 # Loop over old err attributes. 9099 for err_attr in err_attr_list: 9100 if hasattr(cur_spin, err_attr): 9101 delattr(cur_spin, err_attr) 9102 9103 # Loop over the simulated attributes. 9104 for sim_attr in sim_attr_list: 9105 if hasattr(cur_spin, sim_attr): 9106 delattr(cur_spin, sim_attr) 9107 9108 self.interpreter.monte_carlo.setup(number=number) 9109 self.interpreter.monte_carlo.create_data() 9110 self.interpreter.monte_carlo.initial_values() 9111 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints) 9112 self.interpreter.eliminate() 9113 self.interpreter.monte_carlo.error_analysis() 9114 9115 est_key = '%i'%number 9116 est_keys.append(est_key) 9117 9118 # Collect data. 9119 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9120 # Add key for estimate. 9121 my_dic[spin_id][est_key] = {} 9122 9123 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9124 # Generate the param_key. 9125 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9126 9127 # Add key to dic. 9128 my_dic[spin_id][est_key][param_key] = {} 9129 9130 # Get the value. 9131 # Loop over err attributes. 9132 for err_attr in err_attr_list: 9133 if hasattr(cur_spin, err_attr): 9134 get_err_attr = getattr(cur_spin, err_attr)[param_key] 9135 else: 9136 get_err_attr = 0.0 9137 9138 # Save to dic. 9139 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 9140 9141 # Set what to extract. 9142 err_attr = err_attr_list[0] 9143 9144 # Define list with text. 9145 text_list = [] 9146 9147 # Now loop through the data. 9148 for spin_id in spin_id_list: 9149 for est_key in est_keys: 9150 # Define list to pickup data. 9151 r2eff_err_list = [] 9152 9153 for param_key in param_key_list: 9154 # Get the value. 9155 r2eff_err = my_dic[spin_id][est_key][param_key][err_attr] 9156 9157 # Add to list. 9158 r2eff_err_list.append(r2eff_err) 9159 9160 # Sum the list 9161 sum_array = sum(array(r2eff_err_list)) 9162 9163 # Join floats to string. 9164 r2eff_err_str = " ".join(format(x, "2.3f") for x in r2eff_err_list) 9165 9166 # Define print string. 9167 text = "%8s %s sum= %2.3f" % (est_key, r2eff_err_str, sum_array) 9168 text_list.append(text) 9169 9170 9171 # Now print. 9172 filepath = NamedTemporaryFile(delete=False).name 9173 # Open the files for testing. 9174 w_file = open(filepath, 'w') 9175 9176 print("Printing the estimated R2eff error as function of estimation from Co-variance and number of Monte-Carlo simulations.") 9177 9178 for text in text_list: 9179 # Print. 9180 print(text) 9181 9182 # Write to file. 9183 w_file.write(text+"\n") 9184 9185 # Close files 9186 w_file.close() 9187 9188 print("Filepath is: %s"%filepath) 9189 print("Start 'gnuplot' and write:") 9190 print("set term dumb") 9191 print("plot '%s' using 1:17 title 'R2eff error as function of MC number' w linespoints "%filepath)
9192 9193
9194 - def verify_r1rho_kjaergaard_missing_r1(self, models=None, result_dir_name=None, r2eff_estimate=None):
9195 """Verification of test_r1rho_kjaergaard_missing_r1.""" 9196 9197 # Check the kex value of residue 52 9198 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 9199 9200 # Print results for each model. 9201 print("\n\n################") 9202 print("Printing results") 9203 print("################\n") 9204 for model in models: 9205 # Skip R2eff model. 9206 if model == MODEL_R2EFF: 9207 continue 9208 9209 # Switch to pipe. 9210 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 9211 print("\nModel: %s" % (model)) 9212 9213 # Loop over the spins. 9214 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9215 # Generate spin string. 9216 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9217 9218 # Loop over the parameters. 9219 print("Optimised parameters for spin: %s" % (spin_string)) 9220 for param in cur_spin.params + ['chi2']: 9221 # Get the value. 9222 if param in ['r1', 'r2']: 9223 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 9224 # Generate the R20 key. 9225 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 9226 9227 # Get the value. 9228 value = getattr(cur_spin, param)[r20_key] 9229 9230 # Print value. 9231 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 9232 9233 # Compare values. 9234 if spin_id == ':52@N': 9235 if param == 'r1': 9236 if model == MODEL_NOREX: 9237 if r2eff_estimate == 'direct': 9238 self.assertAlmostEqual(value, 1.46138805) 9239 elif r2eff_estimate == 'MC2000': 9240 self.assertAlmostEqual(value, 1.46328102) 9241 elif r2eff_estimate == 'chi2_pyt': 9242 self.assertAlmostEqual(value, 1.43820629) 9243 elif model == MODEL_DPL94: 9244 if r2eff_estimate == 'direct': 9245 self.assertAlmostEqual(value, 1.44845742) 9246 elif r2eff_estimate == 'MC2000': 9247 self.assertAlmostEqual(value, 1.45019848) 9248 elif r2eff_estimate == 'chi2_pyt': 9249 self.assertAlmostEqual(value, 1.44666512) 9250 elif model == MODEL_TP02: 9251 if r2eff_estimate == 'direct': 9252 self.assertAlmostEqual(value, 1.54354392) 9253 elif r2eff_estimate == 'MC2000': 9254 self.assertAlmostEqual(value, 1.54352369) 9255 elif r2eff_estimate == 'chi2_pyt': 9256 self.assertAlmostEqual(value, 1.55964020) 9257 elif model == MODEL_TAP03: 9258 if r2eff_estimate == 'direct': 9259 self.assertAlmostEqual(value, 1.54356410) 9260 elif r2eff_estimate == 'MC2000': 9261 self.assertAlmostEqual(value, 1.54354367) 9262 elif r2eff_estimate == 'chi2_pyt': 9263 self.assertAlmostEqual(value, 1.55967157) 9264 elif model == MODEL_MP05: 9265 if r2eff_estimate == 'direct': 9266 self.assertAlmostEqual(value, 1.54356416) 9267 elif r2eff_estimate == 'MC2000': 9268 self.assertAlmostEqual(value, 1.54354372) 9269 elif r2eff_estimate == 'chi2_pyt': 9270 self.assertAlmostEqual(value, 1.55967163) 9271 elif model == MODEL_NS_R1RHO_2SITE: 9272 if r2eff_estimate == 'direct': 9273 self.assertAlmostEqual(value, 1.41359221, 5) 9274 elif r2eff_estimate == 'MC2000': 9275 self.assertAlmostEqual(value, 1.41321968, 5) 9276 elif r2eff_estimate == 'chi2_pyt': 9277 self.assertAlmostEqual(value, 1.36303129, 5) 9278 9279 elif param == 'r2': 9280 if model == MODEL_NOREX: 9281 if r2eff_estimate == 'direct': 9282 self.assertAlmostEqual(value, 11.48392439) 9283 elif r2eff_estimate == 'MC2000': 9284 self.assertAlmostEqual(value, 11.48040934) 9285 elif r2eff_estimate == 'chi2_pyt': 9286 self.assertAlmostEqual(value, 11.47224488) 9287 elif model == MODEL_DPL94: 9288 if r2eff_estimate == 'direct': 9289 self.assertAlmostEqual(value, 10.15688372, 6) 9290 elif r2eff_estimate == 'MC2000': 9291 self.assertAlmostEqual(value, 10.16304887, 6) 9292 elif r2eff_estimate == 'chi2_pyt': 9293 self.assertAlmostEqual(value, 9.20037797, 6) 9294 elif model == MODEL_TP02: 9295 if r2eff_estimate == 'direct': 9296 self.assertAlmostEqual(value, 9.72654896, 6) 9297 elif r2eff_estimate == 'MC2000': 9298 self.assertAlmostEqual(value, 9.72772726, 6) 9299 elif r2eff_estimate == 'chi2_pyt': 9300 self.assertAlmostEqual(value, 9.53948340, 6) 9301 elif model == MODEL_TAP03: 9302 if r2eff_estimate == 'direct': 9303 self.assertAlmostEqual(value, 9.72641887, 6) 9304 elif r2eff_estimate == 'MC2000': 9305 self.assertAlmostEqual(value, 9.72759374, 6) 9306 elif r2eff_estimate == 'chi2_pyt': 9307 self.assertAlmostEqual(value, 9.53926913, 6) 9308 elif model == MODEL_MP05: 9309 if r2eff_estimate == 'direct': 9310 self.assertAlmostEqual(value, 9.72641723, 6) 9311 elif r2eff_estimate == 'MC2000': 9312 self.assertAlmostEqual(value, 9.72759220, 6) 9313 elif r2eff_estimate == 'chi2_pyt': 9314 self.assertAlmostEqual(value, 9.53926778, 6) 9315 elif model == MODEL_NS_R1RHO_2SITE: 9316 if r2eff_estimate == 'direct': 9317 self.assertAlmostEqual(value, 9.34531535, 5) 9318 elif r2eff_estimate == 'MC2000': 9319 self.assertAlmostEqual(value, 9.34602793, 5) 9320 elif r2eff_estimate == 'chi2_pyt': 9321 self.assertAlmostEqual(value, 9.17631409, 5) 9322 9323 # For all other parameters. 9324 else: 9325 # Get the value. 9326 value = getattr(cur_spin, param) 9327 9328 # Print value. 9329 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 9330 9331 # Compare values. 9332 if spin_id == ':52@N': 9333 if param == 'phi_ex': 9334 if model == MODEL_DPL94: 9335 if r2eff_estimate == 'direct': 9336 self.assertAlmostEqual(value, 0.07599563) 9337 elif r2eff_estimate == 'MC2000': 9338 self.assertAlmostEqual(value, 0.07561937) 9339 elif r2eff_estimate == 'chi2_pyt': 9340 self.assertAlmostEqual(value, 0.12946061) 9341 9342 elif param == 'pA': 9343 if model == MODEL_TP02: 9344 if r2eff_estimate == 'direct': 9345 self.assertAlmostEqual(value, 0.88827040) 9346 elif r2eff_estimate == 'MC2000': 9347 self.assertAlmostEqual(value, 0.88807487) 9348 elif r2eff_estimate == 'chi2_pyt': 9349 self.assertAlmostEqual(value, 0.87746233) 9350 elif model == MODEL_TAP03: 9351 if r2eff_estimate == 'direct': 9352 self.assertAlmostEqual(value, 0.88828922) 9353 elif r2eff_estimate == 'MC2000': 9354 self.assertAlmostEqual(value, 0.88809318) 9355 elif r2eff_estimate == 'chi2_pyt': 9356 self.assertAlmostEqual(value, 0.87747558) 9357 elif model == MODEL_MP05: 9358 if r2eff_estimate == 'direct': 9359 self.assertAlmostEqual(value, 0.88828924, 6) 9360 elif r2eff_estimate == 'MC2000': 9361 self.assertAlmostEqual(value, 0.88809321) 9362 elif r2eff_estimate == 'chi2_pyt': 9363 self.assertAlmostEqual(value, 0.87747562) 9364 elif model == MODEL_NS_R1RHO_2SITE: 9365 if r2eff_estimate == 'direct': 9366 self.assertAlmostEqual(value, 0.94504369, 6) 9367 elif r2eff_estimate == 'MC2000': 9368 self.assertAlmostEqual(value, 0.94496541, 6) 9369 elif r2eff_estimate == 'chi2_pyt': 9370 self.assertAlmostEqual(value, 0.92084707, 6) 9371 9372 elif param == 'dw': 9373 if model == MODEL_TP02: 9374 if r2eff_estimate == 'direct': 9375 self.assertAlmostEqual(value, 1.08875840, 6) 9376 elif r2eff_estimate == 'MC2000': 9377 self.assertAlmostEqual(value, 1.08765638, 6) 9378 elif r2eff_estimate == 'chi2_pyt': 9379 self.assertAlmostEqual(value, 1.09753230, 6) 9380 elif model == MODEL_TAP03: 9381 if r2eff_estimate == 'direct': 9382 self.assertAlmostEqual(value, 1.08837238, 6) 9383 elif r2eff_estimate == 'MC2000': 9384 self.assertAlmostEqual(value, 1.08726698, 6) 9385 elif r2eff_estimate == 'chi2_pyt': 9386 self.assertAlmostEqual(value, 1.09708821, 6) 9387 elif model == MODEL_MP05: 9388 if r2eff_estimate == 'direct': 9389 self.assertAlmostEqual(value, 1.08837241, 6) 9390 elif r2eff_estimate == 'MC2000': 9391 self.assertAlmostEqual(value, 1.08726706, 6) 9392 elif r2eff_estimate == 'chi2_pyt': 9393 self.assertAlmostEqual(value, 1.09708832, 6) 9394 elif model == MODEL_NS_R1RHO_2SITE: 9395 if r2eff_estimate == 'direct': 9396 self.assertAlmostEqual(value, 1.56001812, 5) 9397 elif r2eff_estimate == 'MC2000': 9398 self.assertAlmostEqual(value, 1.55833321, 5) 9399 elif r2eff_estimate == 'chi2_pyt': 9400 self.assertAlmostEqual(value, 1.36406712, 5) 9401 9402 elif param == 'kex': 9403 if model == MODEL_DPL94: 9404 if r2eff_estimate == 'direct': 9405 self.assertAlmostEqual(value/1e5, 4460.43711569/1e5, 7) 9406 elif r2eff_estimate == 'MC2000': 9407 self.assertAlmostEqual(value/1e5, 4419.03917195/1e5, 7) 9408 elif r2eff_estimate == 'chi2_pyt': 9409 self.assertAlmostEqual(value/1e5, 6790.22736344/1e5, 7) 9410 elif model == MODEL_TP02: 9411 if r2eff_estimate == 'direct': 9412 self.assertAlmostEqual(value/1e5, 4921.28602757/1e5, 7) 9413 elif r2eff_estimate == 'MC2000': 9414 self.assertAlmostEqual(value/1e5, 4904.70144883/1e5, 7) 9415 elif r2eff_estimate == 'chi2_pyt': 9416 self.assertAlmostEqual(value/1e5, 5146.20306591/1e5, 7) 9417 elif model == MODEL_TAP03: 9418 if r2eff_estimate == 'direct': 9419 self.assertAlmostEqual(value/1e5, 4926.42963491/1e5, 7) 9420 elif r2eff_estimate == 'MC2000': 9421 self.assertAlmostEqual(value/1e5, 4909.86877150/1e5, 7) 9422 elif r2eff_estimate == 'chi2_pyt': 9423 self.assertAlmostEqual(value/1e5, 5152.51105814/1e5, 7) 9424 elif model == MODEL_MP05: 9425 if r2eff_estimate == 'direct': 9426 self.assertAlmostEqual(value/1e5, 4926.44236315/1e5, 7) 9427 elif r2eff_estimate == 'MC2000': 9428 self.assertAlmostEqual(value/1e5, 4909.88110195/1e5, 7) 9429 elif r2eff_estimate == 'chi2_pyt': 9430 self.assertAlmostEqual(value/1e5, 5152.52097111/1e5, 7) 9431 elif model == MODEL_NS_R1RHO_2SITE: 9432 if r2eff_estimate == 'direct': 9433 self.assertAlmostEqual(value/1e5, 5628.66061488/1e5, 6) 9434 elif r2eff_estimate == 'MC2000': 9435 self.assertAlmostEqual(value/1e5, 5610.20221435/1e5, 6) 9436 elif r2eff_estimate == 'chi2_pyt': 9437 self.assertAlmostEqual(value/1e5, 5643.34067090/1e5, 6) 9438 9439 elif param == 'chi2': 9440 if model == MODEL_NOREX: 9441 if r2eff_estimate == 'direct': 9442 self.assertAlmostEqual(value, 848.42016907, 5) 9443 elif r2eff_estimate == 'MC2000': 9444 self.assertAlmostEqual(value, 3363.95829122, 5) 9445 elif r2eff_estimate == 'chi2_pyt': 9446 self.assertAlmostEqual(value, 5976.49946726, 5) 9447 elif model == MODEL_DPL94: 9448 if r2eff_estimate == 'direct': 9449 self.assertAlmostEqual(value, 179.47041241) 9450 elif r2eff_estimate == 'MC2000': 9451 self.assertAlmostEqual(value, 710.24767560) 9452 elif r2eff_estimate == 'chi2_pyt': 9453 self.assertAlmostEqual(value, 612.72616697, 5) 9454 elif model == MODEL_TP02: 9455 if r2eff_estimate == 'direct': 9456 self.assertAlmostEqual(value, 29.33882530, 6) 9457 elif r2eff_estimate == 'MC2000': 9458 self.assertAlmostEqual(value, 114.47142772, 6) 9459 elif r2eff_estimate == 'chi2_pyt': 9460 self.assertAlmostEqual(value, 250.50838162, 5) 9461 elif model == MODEL_TAP03: 9462 if r2eff_estimate == 'direct': 9463 self.assertAlmostEqual(value, 29.29050673, 6) 9464 elif r2eff_estimate == 'MC2000': 9465 self.assertAlmostEqual(value, 114.27987534) 9466 elif r2eff_estimate == 'chi2_pyt': 9467 self.assertAlmostEqual(value, 250.04050719, 5) 9468 elif model == MODEL_MP05: 9469 if r2eff_estimate == 'direct': 9470 self.assertAlmostEqual(value, 29.29054301, 6) 9471 elif r2eff_estimate == 'MC2000': 9472 self.assertAlmostEqual(value, 114.28002272) 9473 elif r2eff_estimate == 'chi2_pyt': 9474 self.assertAlmostEqual(value, 250.04077478, 5) 9475 elif model == MODEL_NS_R1RHO_2SITE: 9476 if r2eff_estimate == 'direct': 9477 self.assertAlmostEqual(value, 34.44010543, 6) 9478 elif r2eff_estimate == 'MC2000': 9479 self.assertAlmostEqual(value, 134.14368365) 9480 elif r2eff_estimate == 'chi2_pyt': 9481 self.assertAlmostEqual(value, 278.55121388, 5) 9482 9483 9484 # Print the final pipe. 9485 model = 'final' 9486 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 9487 print("\nFinal pipe") 9488 9489 # Loop over the spins. 9490 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9491 # Generate spin string. 9492 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9493 9494 # Loop over the parameters. 9495 print("Optimised model for spin: %s" % (spin_string)) 9496 param = 'model' 9497 9498 # Get the value. 9499 value = getattr(cur_spin, param) 9500 print("%-10s %-6s %-6s %6s" % ("Parameter:", param, "Value:", value)) 9501 9502 9503 ### Now check some of the written out files. 9504 file_names = ['r1rho_prime', 'r1'] 9505 9506 for file_name_i in file_names: 9507 9508 # Make the file name. 9509 file_name = "%s.out" % file_name_i 9510 9511 # Get the file path. 9512 file_path = get_file_path(file_name, result_dir_name + sep + model) 9513 9514 # Test the file exists. 9515 print("Testing file access to: %s"%file_path) 9516 self.assert_(access(file_path, F_OK)) 9517 9518 # Now open, and compare content, line by line. 9519 file_prod = open(file_path) 9520 lines_prod = file_prod.readlines() 9521 file_prod.close() 9522 9523 # Loop over the lines. 9524 for i, line in enumerate(lines_prod): 9525 # Make the string test 9526 line_split = line.split() 9527 9528 # Continue for comment lines. 9529 if line_split[0] == "#": 9530 print(line), 9531 continue 9532 9533 # Assign the split of the line. 9534 mol_name, res_num, res_name, spin_num, spin_name, val, sd_error = line_split 9535 print(mol_name, res_num, res_name, spin_num, spin_name, val, sd_error) 9536 9537 if res_num == '52': 9538 # Assert that the value is not None. 9539 self.assertNotEqual(val, 'None')
9540